Skip to content
Merged
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
5 changes: 5 additions & 0 deletions docs/smart-accounts/3-custom-instruction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ Only function calls with specific parameter values included can be registered.
That means that a new custom instruction needs to be registered for each unique action (though this can be done just seconds in advance).
It is also the reason why special FAsset actions have their own IDs, instead of defaulting to the custom call - it allows us to also specify certain parameters within the instructions on XRPL.

:::warning
Encoding calldata by hand is error prone.
It is recommended to use established libraries, or an [online tool](https://abi.hashex.org/) (if you want to quickly check something).
:::

## Call hash

To produce the custom instructions calldata, we first ABI encode the array of the `IMasterAccountController.CustomInstruction` struct.
Expand Down
26 changes: 24 additions & 2 deletions docs/smart-accounts/guides/01-fsa-cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ That number of lots of FXRP are burned from the user's smart account, and the sa
### `mint`

Mints a number of `lots` of FXRP to the user's smart account.
The script first reserves collateral with the agent with the `address`, by sending a `reserveCollateral` instruction.
The script first reserves collateral with the agent with the `address` (if you are unsure what agent to choose on coston2, use `0x55c815260cBE6c45Fe5bFe5FF32E3C7D746f14dC`), by sending a `reserveCollateral` instruction.
It then sends a `lots` amount of XRP to the agent's underlying address.
An executor, determined by the `MasterAccountController`, will complete the minting process, and `lots` of FXRP will be minted to the user's smart account.

Expand All @@ -114,7 +114,7 @@ Make a transaction to the `address`, paying the `value`, and attaching the `call
The `calldata` is the encoding of a function and its argument values, on the smart contract at the `address.

```sh
./smart_accounts.py bridge deposit -a <address> -v <value> -d <calldata>
./smart_accounts.py bridge custom -a <address> -v <value> -d <calldata>
```

Before making a transaction on XRPL with the necessary instructions, this command performs an additional step.
Expand All @@ -123,6 +123,13 @@ Then, it calls the `registerCustomInstruction` function of the `MasterAccountCon

Thus, it both registers a custom instruction with the `MasterAccountController` contract and retrieves the required `callHash`, which it can then send to the operator's XRPL address as instructions.

You can also use the command with json file containing an array of custom instructions.
Two provided json files in `json_examples/` directory demonstrate the expected format.

```sh
./smart_accounts.py bridge custom json_example/sendFXRPCoston.json
```

## `debug` command

The `debug` command offers some utility options for running the CLI.
Expand All @@ -141,6 +148,12 @@ The `seed` is a string representing an XRPL account.
./smart_accounts.py debug mock-custom -s <seed> -a <address> -v <value> -d <calldata>
```

As with the `custom` command, you can also use a json file containing an array of custom instructions.

```sh
./smart_accounts.py debug mock-custom -s <seed> json_example/sendFXRPCoston.json
```

### `check-status`

Check the status of the XRPL transaction with the `xrpl_hash`.
Expand Down Expand Up @@ -168,3 +181,12 @@ This is equivalent to running the following commands:
./smart_accounts.py bridge claim-withdraw
./smart_accounts.py bridge redeem -l <mint>
```

## `encode` command

The `encode` command prints encoded memo fields that can be used in XRPL transactions to instruct the operator to perform certain actions on Flare.

```sh
./smart_accounts.py encode custom json_example/requestRedemption.json
./smart_accounts.py encode mint -l 1
```
17 changes: 14 additions & 3 deletions docs/smart-accounts/guides/02-custom-instructions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ We want to send `1 FLR` to the contract, and save it under number `42`.
The address of the `Foo` contract is `0x296432C15504Ed465fAce11E54Ce4aac50cCd8A3`.
Using an online ABI-encoding tool, we get that the following hash for the `bar` function, with `42` as input: `0x0423a132000000000000000000000000000000000000000000000000000000000000002a`.

:::warning
Encoding calldata by hand is error prone.
It is recommended to use established libraries, or an [online tool](https://abi.hashex.org/) (if you want to quickly check something).
:::

There are two ways we can go about developing the custom instructions.
We will start with an approach, which is what the production code would take.
Afterwards, we will use the the mock functions to speed up the development.
Expand All @@ -97,14 +102,14 @@ It is necessary to send some instructions, because that is what creates an accou
We then need to retrieve the smart account address.

```sh
./smart_accounts personal-account --from-env print
./smart_accounts.py personal-account --from-env print
```

With the address, we can go to the [Flare faucet](https://faucet.flare.network/coston2) and request C2FLR for the smart account address.
We can also do this through the CLI.

```sh
./smart_accounts personal-account --from-env faucet
./smart_accounts.py personal-account --from-env faucet
```

Afterwards, we can run the following command again.
Expand All @@ -121,12 +126,18 @@ First, we need to create a mock account, which we do with the command.
This will only work if our Flare address has sufficient funds.

```sh
./smart_accounts mock-create-fund --seed "mockAccount" --value 1
./smart_accounts.py debug mock-create-fund --seed "mockAccount" --value 1
```

Here we arbitrarily chose the name `mockAccount` as the account address.
Behind the scenes, the string `mockAccount` will be concatenated with our Flare address.

You can check the associated account with the command:

```sh
./smart_accounts.py debug mock-print -s <seed>
```

Then, we execute the custom instructions.
We use the string `mockAccount` as the seed.

Expand Down
Loading