Skip to content
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

Feat/soroban snippets #1247

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Soroban GMP Example

## Soroban to EVM

## EVM to Soroban
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Soroban ITS
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { Callout } from "../../../../../components/callout";

# Soroban Contracts

The core contracts for Axelar's integration with Stellar Soroban can be found at the [axelar-cgp-soroban](https://github.com/axelarnetwork/axelar-cgp-soroban) repository.

The Rust based GMP contracts can be thought of similarly to their [EVM](/dev/general-message-passing/gmp-messages/) counterparts.

At the core of there are two main contracts involved in sending a GMP message, these are the [Gateway Contract](https://github.com/axelarnetwork/axelar-cgp-soroban/tree/main/contracts/axelar-gateway) and the [Gas Service](https://github.com/axelarnetwork/axelar-cgp-soroban/tree/main/contracts/axelar-gas-service).

## Soroban Gateway
The Gateway facilitates sending and receiving of cross-chain messages to other chains via the Axelar Network.

For sending a GMP message, the `callContract()` function needs to be triggered.

### CallContract
The `callContract` function triggers your cross-chain message from Stellar to the Axelar Network. When sending a cross-chain message you must specify the destination of your cross-chain message and a given payload.

<Callout emoji="💡">
Note: In Soroban, you don't need to pass the `env` explicitly when writing contract functions; it is automatically provided to the contract entry points
</Callout>

The `callContract` function takes five parameters.
1. `env`: Standard soroban [env](https://developers.stellar.org/docs/learn/encyclopedia/contract-development/environment-concepts) that provides access to the environment the contract is executing within.
benjamin852 marked this conversation as resolved.
Show resolved Hide resolved
1. `caller`: The sender of the contract call.
1. `destination_chain`: Name of the chain the message is being sent to.
1. `destination_address`: Address on the destination chain the message is being sent to.
1. `payload`: A `bytes` representation of the cross-chain message being sent.

```rust
pub fn call_contract(
env: Env,
caller: Address,
destination_chain: String,
destination_address: String,
payload: Bytes,
){}
```

## Soroban Gas Service
The Gas Service handles cross-chain gas payment when making a GMP request.

When sending a GMP message before triggering the `call_contract()` function on the Gateway, the `pay_gas_for_contract_call()` must be triggered first to pay for the cross-chain transaction.

### PayGasForContractCall()
The `pay_gas_for_contract_call()` allows users to pay for the entirety of the cross-chain transaction in a given token.

The `pay_gas_for_contract_call()` takes seven parameters.
1. `env`: Standard soroban [env](https://developers.stellar.org/docs/learn/encyclopedia/contract-development/environment-concepts) that provides access to the environment the contract is executing within.
benjamin852 marked this conversation as resolved.
Show resolved Hide resolved
1. `sender`: The sender of the gas payment call.
1. `destination_chain`: Name of the chain the message is being sent to.
1. `destination_address`: Address on the destination chain the message is being sent to.
1. `payload`: A `bytes` representation of the cross-chain message being sent.
1. `refund_address`: An address to be refunded if gas amount was overpaid.
1. `token`: The token being used for payment

Note: The expected [token](https://github.com/axelarnetwork/axelar-cgp-soroban/blob/main/packages/axelar-soroban-std/src/types.rs#L5) is a struct type that requires an `address` and `amount`.

```rust
pub fn pay_gas_for_contract_call(
env: Env,
sender: Address,
destination_chain: String,
destination_address: String,
payload: Bytes,
refund_address: Address,
token: Token,
) -> Result<(), ContractError> {}
```

## Soroban Executable
The [Executable](https://github.com/axelarnetwork/axelar-cgp-soroban/blob/main/contracts/axelar-gateway/src/executable.rs#L9) is a Rust Trait (not an individual contract) that will be used to execute a cross-chain call on a Soroban dapp when Stellar is the receiving chain of a cross-chain message.

### Execute
The `execute()` function will be triggered by an Axelar relayer when the cross-chain message arrives. Your contract should implement the `execute()` function to handle the incoming cross-chain GMP data.

The `execute()` function takes five parameters.
1. `env`: Standard soroban [env](https://developers.stellar.org/docs/learn/encyclopedia/contract-development/environment-concepts) that provides access to the environment the contract is executing within.
1. `source_chain`: The source chain where the gmp message is coming from.
1. `message_id`: Identifier for incoming GMP message.
1. `source_address`: The address on the source chain where the gmp message is coming from/
1. `payload`: A `bytes` representation of the cross-chain message being sent.

```rust
fn execute(
env: Env,
source_chain: String,
message_id: String,
source_address: String,
payload: Bytes,
);
```

### Validate & Validate Message
The `validate()` function on the `Executable` will trigger the `validate_message()` that is [defined](https://github.com/axelarnetwork/axelar-cgp-soroban/blob/main/contracts/axelar-gateway/src/contract.rs#L128) on the `Gateway`.

The `validate()` function takes five parameters.
1. `env`: Standard soroban [env](https://developers.stellar.org/docs/learn/encyclopedia/contract-development/environment-concepts) that provides access to the environment the contract is executing within.
1. `source_chain`: The source chain where the gmp message is coming from.
1. `message_id`: Identifier for incoming GMP message.
1. `source_address`: The address on the source chain where the gmp message is coming from/
1. `payload`: A `bytes` representation of the cross-chain message being sent.

```rust
fn validate(
env: Env,
source_chain: String,
message_id: String,
source_address: String,
payload: Bytes,
) {}
```

The `validate()` function will trigger the `validate_message()`, this will confirm that the incoming GMP message is an authenticated message that has been verified by the Amplifier Verifiers.

```rust
pub fn validate_message(
env: Env,
caller: Address,
source_chain: String,
message_id: String,
source_address: String,
payload_hash: BytesN<32>,
) -> bool {}
```

1. `env`: Standard soroban [env](https://developers.stellar.org/docs/learn/encyclopedia/contract-development/environment-concepts) that provides access to the environment the contract is executing within.
1. `caller`: The intended `destination_address` of the contract call.
1. `source_chain`: The source chain where the gmp message is coming from.
1. `message_id`: Identifier for incoming GMP message.
1. `source_address`: The address on the source chain where the gmp message is coming from/
1. `payload`: A `bytes` representation of the cross-chain message being sent.

Returns a `bool` indicating whether the incoming GMP message is valid or not.
19 changes: 18 additions & 1 deletion src/layouts/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export const getNavigation = (section) => {
title: "Send Messages with Tokens",
href: "/dev/general-message-passing/gmp-tokens-with-messages/",
},

{
title: "Gas Service",
children: [
Expand Down Expand Up @@ -232,6 +231,24 @@ export const getNavigation = (section) => {
},
],
},
{
title: "Stellar Soroban GMP",
children: [
{
title: "Soroban Contracts",
href: "/dev/general-message-passing/soroban-gmp/soroban-contracts/"
},
{
title: "GMP Example",
href: "/dev/general-message-passing/soroban-gmp/gmp-message-example/"
},
{
title: "ITS",
href: "/dev/general-message-passing/soroban-gmp/its/"
}
]

},
{
title: "Solidity Utilities",
href: "/dev/solidity-utilities/",
Expand Down