Skip to content

Commit

Permalink
Landing pages for Chain Abstraction Services (#2200)
Browse files Browse the repository at this point in the history
* added landing pages for ca services

* added canhazgas mainnet

* added image
  • Loading branch information
gagdiez authored Aug 8, 2024
1 parent 32b5ca6 commit 2053ee2
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
id: chain-signatures-getting-started
title: Getting Started with Chain Signatures
hide_table_of_contents: true
---

Chain Signatures is a groundbreaking technology built on NEAR that enables NEAR accounts, including smart contracts, to sign and execute transactions across multiple blockchains. This innovation leverages Multi-Party Computation (MPC) and a distributed network of node operators to create joint signatures from arbitrary payloads, allowing NEAR users to control external blockchain accounts.

![img](https://pages.near.org/wp-content/uploads/2024/02/acct-abstraction-blog-1.png)

This technology enhances blockchain interoperability, giving ownership of diverse assets, cross-chain accounts, and data to a single NEAR account.

---

## How Does It Work?

Chain Signatures operates through a series of steps to enable seamless cross-chain transactions:

1. **Deriving Foreign Addresses:**
* Chain Signatures uses derivation paths to represent accounts on foreign blockchains.
* The NEAR account’s name and the derivation path are used to mathematically [derive a unique address](https://docs.near.org/concepts/abstraction/chain-signatures\#derivation-paths-one-account-multiple-chains) for the user on the foreign blockchain.
2. **Creating the Transaction:**
* The client constructs the hash of the transaction to be signed, which varies by the target blockchain.
3. **Requesting the Signature:**
* A NEAR account or smart contract calls the sign method of the MPC smart contract ([v1.signer](https://nearblocks.io/address/v1.signer)) to sign a payload.
4. **Relaying the Signature:**
* The client reconstructs the valid transaction using the signature and broadcasts it to the destination blockchain.

This process eliminates the need for traditional bridges and enables developers to build innovative cross-chain DeFi applications with seamless user experiences.

---

## Use Cases

1. **DeFi on Bitcoin (and other chain without smart contracts)**
* Chain signatures allow NEAR smart contract to program assets on Bitcoin
* Build lending, swaps, runes launchpads, passkey-based Bitcoin wallets, and more
2. **Chain agnostic applications**
* Since chain signatures can sign transactions for all blockchains, developers can support every single chain with just one smart contract
* Multichain DEXs, lending protocols, oracles, derivatives, and more
3. **Multichain account abstraction**
* Users can control assets on all chains with just their NEAR account, and can utilize account abstraction features on any chain including passkeys, key rotation, etc
* Using the multichain gas relayer, users can pay for gas fees on any chain using USDC
4. **Privacy**
* Chain signatures can be used to encrypt and decrypt information in a programmatic way
* This enables privacy applications, and even decrypting information based on ownership of assets/NFTs

---

## How to Get Started?

1. **Familiarize Yourself with Chain Signatures:**
* Understand the [basics of Chain Signatures](https://docs.near.org/concepts/abstraction/chain-signatures) and how they simplify blockchain interactions.
* Review the technical [explainer](https://near.org/blog/unlocking-web3-usability-with-account-aggregation).
2. **Explore the Use Cases:**
* Review [examples of use cases for Chain Signatures](https://pages.near.org/blog/unlocking-multichain-web3-with-near-chain-signatures/), such as Multichain DAO, Multichain NFT Minter, and Bitcoin Runes Airdrop.
3. **Access Resources and Documentation:**
* Visit the [Chain Signatures documentation](https://docs.near.org/build/chain-abstraction/chain-signatures) for detailed technical information and code snippets.
* Check out the [Linktree for Chain Signatures](https://linktr.ee/chainsignatures) for various resources, including demos and tutorials.
4. **Try the Demos:**
* Use the [command-line-based demo](https://github.com/near-examples/chainsig-script) to derive accounts and send transactions on Bitcoin, Ethereum, Doge, and Ripple.
* Check out the [web app demo](https://github.com/near-examples/near-multichain/tree/main).
5. **Engage with the Community:**
* Join the [Chain Abstraction developers’ channel on Telegram](https://t.me/chain\_abstraction) to connect with other developers and get support.

---

## Where to Learn More?

To dive deeper into Chain Signatures and its applications, you can explore the following resources:

* **Technical Blogs and Deep Dives:**
* Read [high-level use cases](https://pages.near.org/blog/unlocking-multichain-web3-with-near-chain-signatures) and technical [explainer](https://near.org/blog/unlocking-web3-usability-with-account-aggregation) posts on the NEAR blog.
* **Community and Support:**
* Engage with the NEAR community on social media platforms like Twitter and participate in discussions to stay updated on the latest developments.
5 changes: 2 additions & 3 deletions docs/2.build/1.chain-abstraction/chain-signatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,19 @@ There are five steps to create a Chain Signature:
![chain-signatures](/docs/assets/welcome-pages/chain-signatures-overview.png)
_Diagram of a chain signature in NEAR_

:::info MPC testnet contracts
:::info MPC Contracts

If you want to try things out, these are the smart contracts available on `testnet`:

- `v1.signer-prod.testnet`: [MPC signer](https://github.com/near/mpc/tree/v0.2.0/contract) contract, latest release, made up of 8 MPC nodes
- `canhazgas.testnet`: [Multichain Gas Station](multichain-gas-relayer/gas-station.md) contract
- `nft.kagi.testnet`: [NFT Chain Key](nft-keys.md) contract

:::

:::info MPC mainnet contracts

- `v1.signer`: [MPC signer](https://github.com/near/mpc/tree/v0.2.0/contract) contract, latest release, made up of 8 MPC nodes

- `canhazgas.near`: [Multichain Gas Station](multichain-gas-relayer/gas-station.md) contract
:::

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Users who wish to get transactions signed and relayed by this contract and its a

If you want to try things out, this smart contract is available on:
- testnet: `canhazgas.testnet`
- mainnet: `TBD`
- mainnet: `canhazgas.near`

:::

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
id: getting-started
title: "Multichain Gas Relayer: Getting Started Guide"
hide_table_of_contents: true
---

The Multichain Gas Relayer provides gas abstraction for foreign chains outside of NEAR. This system, in conjunction with NEAR Chain Signatures, allows NEAR users to transact on other blockchains and pay for gas using NEAR, USDC, USDT, or other NEAR-based tokens from a single NEAR account.

![img](https://pages.near.org/wp-content/uploads/2024/02/acct-abstraction-blog-1.png)

Chain Signatures lets users manage remote accounts and transact on any blockchain from a single NEAR account. The Multichain Gas Relayer further simplifies this process by eliminating the need for users to acquire native gas tokens to transact on other chains.


---

## Why did NEAR create the Multichain Gas Relayer?

NEAR's mission is to build blockchain infrastructure for Chain Abstracted applications. Chain abstraction aims to make blockchain technology more user-friendly by simplifying interactions. A key step in achieving this is reducing the complexity of paying for transaction gas across different blockchains. Users should be able to pay for cross-chain transactions with a single asset or have the gas fees fully sponsored on their behalf.

---

## How does it work?

The Multichain Gas Relayer has 3 core components:

1. **Gas Station Smart Contract**: A smart contract on NEAR that manages the creation, signing, of transactions to foreign chains. It also handles gas fee calculations and collects NEAR tokens for gas payments on foreign chains.
2. **Multichain Relayer Server**: This server coordinates the relaying of transactions between NEAR and other blockchains. It listens for signed transaction payloads and submits them to the appropriate foreign chain RPCs.
3. **Chain Signatures**: A network of distributed Multi-Party Computation (MPC) signers that cooperatively sign transactions. This ensures secure transaction signing and validation on the NEAR blockchain before relaying to foreign chains.

### System Workflow

1. **Transaction Creation**: Users initiate a transaction on NEAR, specifying the foreign chain transaction and attaching NEAR tokens to cover gas fees on the foreign chain. This transaction is sent to the Gas Station Contract.
2. **Transaction Signing**: The Gas Station Contract invokes Chain Signatures MPC signing service to sign the transaction. This step may require multiple calls due to gas limitations on NEAR, especially for complex transactions.
3. **Event Emission and Indexing**: Once the transactions are signed, the Gas Station Contract emits an event. The Gas Station Event Indexer picks up this event and triggers the Multichain Relayer Server to relay the signed transactions.
4. **Relaying Transactions**: The Multichain Relayer Server first sends a funding transaction to ensure the user’s account on the foreign chain has sufficient gas. Once confirmed, it sends the user’s originally intended signed transaction to the foreign chain for execution.

---

## Example Real-World Flow

* Alice has an alice.near account that maps to a remote Optimism (OP) address, 0xabc
* Alice wants to interact with a Farcaster application on OP using her NEAR account, but she prefers to pay for gas with assets she has on hand, specifically USDT
* Alice initiates an on-chain action on Farcaster from her NEAR account. She sends the transaction to a gas station smart contract, including the OP transaction payload in the arguments and attaching the necessary USDT amount for the cross-chain gas payment
* The transaction bundle is sent to the NEAR gas station contract, which then forwards it to the NEAR MPC signing service. This bundle includes (1) the transaction to fund the user's 0xabc address with the ETH needed for gas, and (2) the user's original transaction to take action on the Farcaster application
* The MPC service will sign both transactions and forward the signed transactions back to the gas station contract
* The relayer operator will observe the events (signed transactions) emitted from the gas station contract and submit them to the Optimism network. This process starts by initiating a fund transfer from a treasury paymaster account on Optimism that holds ETH. The paymaster account will transfer ETH to the user's 0xabc address, equivalent to the USDT originally sent by the user
* Then the relayer will submit the final transaction, and the originally intended Farcaster transaction will be executed from the user's 0xabc address, using ETH to cover the gas

---

## What chains are supported?

The NEAR Multichain Gas Relayer supports cross-chain gas abstraction on Base, Optimism, Arbitrum and Binance Smart Chain, and Ethereum. These chains were selected based on multiple factors including interest from key partners, low gas fees, and fast finality for transactions. Support for EDDSA chains like Solana will be coming soon in conjunction with EDDSA support for NEAR chain signatures.

---

## Where can I go to learn more?

* Visit our [docs](https://docs.near.org/build/chain-abstraction/multichain-gas-relayer/overview) to learn more about how to integrate the Multichain Gas Relayer into your product
* Join the NEAR Chain Abstraction [developer group](https://t.me/chain\_abstraction) on Telegram to ask questions and discuss ideas with other developers.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ For independent deployments of gas station contracts, generally, nonce synchroni
1. The wallet sends a NEAR transaction to the gas station contract that contains 2 actions:
1. A transfer of `NEAR` (or FT Transfer in the future) to cover gas on the foreign chain
2. A `create_transaction` function call to the gas station contract `canhazgas.testnet` containing the unsigned foreign chain transaction to be signed by the MPC signing service, assuming the unsigned transaction passes validation.
> (note: `mainnet` contract address TBD)
> (note: `mainnet` contract address is `canhazgas.near`)
2. The Gas Station Contract calls the MPC signing service to sign both a funding transaction, which ensures the user's foreign chain account has sufficient gas to execute the desired transaction, and signs the unsigned foreign chain transaction.
3. Upon receipt of both the signed transactions, the Gas Station Contract emits an event which is picked up by the indexer, which then calls the `/send_funding_and_user_signed_txns` with the 2 signed transactions from the indexer.
4. The multichain relayer server sends the funding transaction to the foreign chain RPC to fund the user's account with gas.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ To run the [Gas Station indexer](https://github.com/near/gas-station-event-index
make install
```

3. Update the [`config.toml`](https://github.com/near/gas-station-event-indexer/blob/main/config.toml) configuration file with appropriate values
3. Update the [`config.toml`](https://github.com/near/gas-station-event-indexer/blob/main/config.toml) configuration file with appropriate values (use `canhazgas.near` for mainnet)
```
network = "testnet"
# gas station contract account id
Expand Down Expand Up @@ -135,7 +135,7 @@ The following instructions are only need to be called once to initialize the acc
mint json-args {} prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' \
sign-as <account_id>.testnet network-config testnet sign-with-keychain send
```
3. Approve the Gas Station for this Token
3. Approve the Gas Station for this Token (use or use `canhazgas.near` for mainnet):
```shell
near contract call-function as-transaction v2.nft.kagi.testnet \
ckt_approve_call json-args '{"token_id":"<token_id>","account_id":"canhazgas.testnet","msg":""}' \
Expand All @@ -145,7 +145,7 @@ The following instructions are only need to be called once to initialize the acc
### Manual test steps
1. Get paymaster info for the chain you want to send to from the gas station contract, then optionally manually set nonces:
1. Get paymaster info for the chain you want to send to from the gas station contract, then optionally manually set nonces (use `canhazgas.near` for mainnet):
```shell
near contract call-function as-transaction canhazgas.testnet \
get_paymasters json-args '{"chain_id": "<chain_id>"}' \
Expand All @@ -165,7 +165,7 @@ The following instructions are only need to be called once to initialize the acc
]
------------------------------------
```
1. You may need to manually set the nonce for the paymaster to be able to send the transaction:
1. You may need to manually set the nonce for the paymaster to be able to send the transaction (use `canhazgas.near` for mainnet):
```shell
near contract call-function as-transaction canhazgas.testnet \
get_paymasters json-args '{"chain_id": "<chain_id>"}' \
Expand Down Expand Up @@ -215,7 +215,7 @@ Python and Rust output different hex RLP encoded transactions.
You should transfer the amount of `NEAR` that's needed to cover gas both on NEAR and on the foreign chain.
You also need to paste in the RLP generated hex for the EVM transaction you want on the other chain generated in step 1.
When it asks you to send or display, choose send.
For example:
For example (use `canhazgas.near` for mainnet):
```shell
near contract call-function as-transaction canhazgas.testnet \
create_transaction json-args '{"transaction_rlp_hex":"eb80851bf08eb000825208947b965bdb7f0464843572eb2b8c17bdf27b720b14872386f26fc1000080808080","use_paymaster":true,"token_id":"<token_id>"}' \
Expand All @@ -232,7 +232,7 @@ Python and Rust output different hex RLP encoded transactions.
}
------------------------------------
```
6. Get the `"id"` from the receipts from the result in the previous step, and use that to call `sign_next` twice:
6. Get the `"id"` from the receipts from the result in the previous step, and use that to call `sign_next` twice (use `canhazgas.near` for mainnet):
```shell
near contract call-function as-transaction canhazgas.testnet \
sign_next json-args '{"id":"<id>"}' \
Expand All @@ -253,7 +253,7 @@ Python and Rust output different hex RLP encoded transactions.
### Optional for testing purposes
Instead of creating a signed transaction and calling the gas station contract to sign it, you can get the recently signed transactions by calling the contract while replacing the `blockheight` with a more recent block height:
Instead of creating a signed transaction and calling the gas station contract to sign it, you can get the recently signed transactions by calling the contract while replacing the `blockheight` with a more recent block height (use `canhazgas.near` for mainnet):
```sh
near contract call-function as-read-only canhazgas.testnet list_signed_transaction_sequences_after json-args '{"block_height":"157111000"}' network-config testnet now
Expand Down
18 changes: 15 additions & 3 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,27 @@ const sidebar = {
]
},
{
"Chain Signatures": [
"type": "category",
"label": "Chain Signatures",
"link": {
"type": "doc",
"id": "build/chain-abstraction/chain-signatures-getting-started"
},
"items": [
"concepts/abstraction/chain-signatures",
'build/chain-abstraction/chain-signatures',
'build/chain-abstraction/nft-chain-keys',
]
},
// 'build/chain-abstraction/wallet',
{
"Multichain Gas Relayer": [
"type": "category",
"label": "Multichain Gas Relayer",
"link": {
"type": "doc",
"id": "build/chain-abstraction/multichain-gas-relayer/getting-started"
},
"items": [
"build/chain-abstraction/multichain-gas-relayer/overview",
"build/chain-abstraction/multichain-gas-relayer/gas-station",
"build/chain-abstraction/multichain-gas-relayer/multichain-server",
Expand Down Expand Up @@ -281,7 +293,7 @@ const sidebar = {
},
{
"Lake Framework": [
"concepts/advanced/near-lake-framework",
"concepts/advanced/near-lake-framework",
"build/data-infrastructure/lake-framework/near-lake",
"build/data-infrastructure/lake-framework/near-lake-state-changes-indexer",
"build/data-infrastructure/lake-framework/migrating-to-near-lake-framework",
Expand Down

0 comments on commit 2053ee2

Please sign in to comment.