# The Staking Proxy Flow for Polkadot

The staking proxy flow for Polkadot will walk your application through the process of adding proxy rights to another account.

### Proxy On-Chain Deposit
Proxies require deposits in the native currency (i.e. DOT) to be created. The deposit is required because adding a proxy requires some storage space on-chain, which must be replicated across every peer in the network.

Once the proxy is removed, both the storage space and the deposited amount are returned.

The required deposit amount for n proxies is equal to:

```
ProxyDepositBase + ProxyDepositFactor
```

Where the **ProxyDepositBase** is the required amount to be reserved for an account to have a proxy list (creates one new item in storage). For every proxy the account has, an additional amount defined by the **ProxyDepositFactor** is reserved as well.

The **ProxyDepositBase** is **20.008 DOT** and the **ProxyDepositFactor** is **0.033 DOT**.

### If Testing on Westend
Please use `5FsrYox6CGyZ7rovGAmn17mJyHXf8QFN82KoGYWz6eHnRRXW` as your proxy account address. For mainnet, please ask Figment.

# Create New Add Staking Proxy Flow
To add a staking proxy, create a new flow with a `POST` request to `/api/v1/flows`.

### URL
```
POST https://api.figment.io/flows
```

### Request
- `flow` : `object`
  - `network_code`\* : `string` Network this flow operates on (ex. `polkadot`).
  - `chain_code`\* : `string` Chain this flow operates on (ex. `westend`).
  - `operation`\* : `string` The operation to perform (ex. `add_proxy`).

JSON

```json
{
    "protocol": "polkadot",
    "network": "westend",
    "operation": "add_proxy"
}
```

### Response
- `id` : `string` ID of the flow.
- `operation` : `string` The Staking API operation being performed by this flow.
- `state` : `string` The current state of the flow.
- `actions` : `array` It includes the `name` & `inputs` of all next possible actions.

- `create_add_proxy_tx`: Use this action to generate an add proxy transaction.

- `proxy_account_address` : The address to which you want to grant proxy rights.
    - `proxied_account_address` : The account whose rights will be proxied.
- `data` : `object` Flow & transaction data.

```json
{
  "id": "d04c0129-50b8-4a44-8df0-b52f2d1d6919",
  "operation": "add_proxy",
  "state": "initialized",
  "actions": [{
    "name": "create_add_proxy_tx",
    "inputs": [{
      "name": "proxy_account_address",
      "display": "Proxy Account Address",
      "description": "",
      "type": "string",
      "validations": [{
        "type": "presence",
        "options": {}
      }],
      "array": false,
      "default_value": null
    }, {
      "name": "proxied_account_address",
      "display": "Proxied Account Address",
      "description": "",
      "type": "string",
      "validations": [{
        "type": "presence",
        "options": {}
      }],
      "array": false,
      "default_value": null
    }]
  }],
  "data": {
    "proxy_account_address": null,
    "proxied_account_address": null,
    "add_proxy_transaction": null
  },
  "protocol": "polkadot",
  "network": "westend",
  "created_at": "2025-03-27T18:03:41.296Z",
  "updated_at": "2025-03-27T18:03:41.296Z"
}
```

# Submit Add Proxy Data
After collecting the required inputs, send a `PUT` request to `/api/v1/flows/[:flow_id]/next` to proceed to the next step.

### URL
```
PUT https://api.figment.io/flows/[:flow_id]/next
```

### Request
- `name`\* : `create_add_proxy_tx`
- `inputs`\* : `object`
  - `proxy_account_address`\* : `string` The address to which you want to add proxy rights.
  - `proxied_account_address`\* : `string` The account whose rights will be proxied.

JSON

```json
{
  "name": "create_add_proxy_tx",
  "inputs": {
    "proxy_account_address": "5FsrYox6CGyZ7rovGAmn17mJyHXf8QFN82KoGYWz6eHnRRXW",
    "proxied_account_address": "5DqYk5FDueD5NFxySRx2co5xg5cEChpsPhQTHUB9uAHERRaE"
  }
}
```

### Response
- `id` : `string` ID of the flow.
- `operation` : `string` The Staking API operation being performed by this flow.
- `state` : `string` The current state of the flow.
- `actions` : `array` It includes the `name` & `inputs` of all next possible actions.
- `data` : `object` Flow & transaction data.

```json
{
    "id": "d04c0129-50b8-4a44-8df0-b52f2d1d6919",
    "operation": "add_proxy",
    "state": "add_proxy_tx_signature",
    "actions": [{
        "name": "refresh_add_proxy_tx",
        "inputs": [{
            "name": "proxy_account_address",
            "display": "Proxy Account Address",
            "description": "",
            "type": "string",
            "validations": [{
                "type": "presence",
                "options": {}
            }],
            "array": false,
            "default_value": "5FsrYox6CGyZ7rovGAmn17mJyHXf8QFN82KoGYWz6eHnRRXW"
        }, {
            "name": "proxied_account_address",
            "display": "Proxied Account Address",
            "description": "",
            "type": "string",
            "validations": [{
                "type": "presence",
                "options": {}
            }],
            "array": false,
            "default_value": "5DqYk5FDueD5NFxySRx2co5xg5cEChpsPhQTHUB9uAHERRaE"
        }]
    }, {
        "name": "sign_add_proxy_tx",
        "inputs": [{
            "name": "transaction_payload",
            "display": "Transaction Payload",
            "description": "",
            "type": "signed_transaction",
            "validations": [],
            "array": false,
            "default_value": null,
            "signers": [
                "5DqYk5FDueD5NFxySRx2co5xg5cEChpsPhQTHUB9uAHERRaE"
            ],
            "transaction_payload": "0xa404160100a8aa7e9be09ceb0d3db02ae159bd105253e553bb6c944de7d4c35dfda4ae772c0300000000"
        }, {
            "name": "signatures",
            "display": "Signatures",
            "description": "",
            "type": "array_of_signatures",
            "validations": [],
            "array": true,
            "default_value": null,
            "element_type": "signature_data",
            "signers": [
                "5DqYk5FDueD5NFxySRx2co5xg5cEChpsPhQTHUB9uAHERRaE"
            ],
            "transaction_payload": "0xa404160100a8aa7e9be09ceb0d3db02ae159bd105253e553bb6c944de7d4c35dfda4ae772c0300000000",
            "signing_payload": "0x160100a8aa7e9be09ceb0d3db02ae159bd105253e553bb6c944de7d4c35dfda4ae772c03000000000048000091880f001b000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423ee143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e00",
            "inputs": [{
                "name": "account_address",
                "display": "Account Address",
                "description": "",
                "type": "string",
                "validations": [{
                    "type": "presence",
                    "options": {}
                }],
                "array": false,
                "default_value": null
            }, {
                "name": "signature",
                "display": "Signature",
                "description": "",
                "type": "string",
                "validations": [{
                    "type": "presence",
                    "options": {}
                }],
                "array": false,
                "default_value": null
            }]
        }]
    }, {
        "name": "confirm_add_proxy_tx_by_hash",
        "inputs": [{
            "name": "hash",
            "display": "Hash",
            "description": "",
            "type": "string",
            "validations": [{
                "type": "presence",
                "options": {}
            }],
            "array": false,
            "default_value": null
        }, {
            "name": "block_number",
            "display": "Block Number",
            "description": "",
            "type": "integer",
            "validations": [],
            "array": false,
            "default_value": null
        }]
    }],
    "data": {
        "proxy_account_address": "5FsrYox6CGyZ7rovGAmn17mJyHXf8QFN82KoGYWz6eHnRRXW",
        "proxied_account_address": "5DqYk5FDueD5NFxySRx2co5xg5cEChpsPhQTHUB9uAHERRaE",
        "add_proxy_transaction": {
            "raw": "0xa404160100a8aa7e9be09ceb0d3db02ae159bd105253e553bb6c944de7d4c35dfda4ae772c0300000000",
            "signing_payload": "0x160100a8aa7e9be09ceb0d3db02ae159bd105253e553bb6c944de7d4c35dfda4ae772c03000000000048000091880f001b000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423ee143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e00",
            "signed": null,
            "hash": null,
            "status": null,
            "error": null,
            "signatures": null,
            "block_time": null,
            "block_number": null,
            "last_valid_block_height": null,
            "proxy": null
        }
    },
    "protocol": "polkadot",
    "network": "westend",
    "created_at": "2025-03-27T18:03:41.296Z",
    "updated_at": "2025-03-27T18:08:54.600Z"
}
```

# Submit Signed Add Proxy Transaction for Broadcast
Before broadcasting the transaction, you must sign the `transaction_payload` you received in the previous step. After signing the transaction, you will `PUT /api/v1/flows/[:flow_id]/next` (as always!) and the Staking API will broadcast the transaction to the Polkadot network.

### URL
```
PUT https://api.figment.io/flows/[:flow_id]/next
```

### Request
- `name`\* : `sign_add_proxy_tx`
- `inputs`\* : `object`
  - `transaction_payload`\* : Signed transaction payload from the previous step's response.
  - `signatures` : `array` of `object` The signatures array can be used **instead of sending a transaction payload** when the signing keys are kept in a custodial solution, such as Fireblocks.

JSON

```json
{
  "name": "sign_add_proxy_tx",
  "inputs": {
    "transaction_payload": "0x3d0284004e6f98e193d7ab454d3fad247b17f76d2249df6ac865a4c7e2b599c49392fd33017cdeb40b087efb56cc5b21b05477c1d3c52d0b4cdcee6cc6bea3d64c689f8439d5aa5776d13e4bde360932fe2b2ae6462709eb76959b3bb4f255c70db3a9498400480000160100a8aa7e9be09ceb0d3db02ae159bd105253e553bb6c944de7d4c35dfda4ae772c0300000000"
  }
}
```

### Response
- `id` : `string` ID of the flow.
- `operation` : `string` The Staking API operation being performed by this flow.
- `state` : `string` The current state of the flow.

- `add_proxy_tx_broadcasting` : Transaction has been broadcast and is waiting confirmation.
  - `registered` : Transaction has been confirmed and the proxy is complete.
- `actions` : `array` It includes the `name` & `inputs` of all next possible actions.
- `data` : `object` Flow & transaction data.

```json
{
  "id": "d04c0129-50b8-4a44-8df0-b52f2d1d6919",
  "operation": "add_proxy",
  "state": "add_proxy_tx_broadcasting",
  "actions": [{
    "name": "wait",
    "estimated_state_change_at": "2025-03-27T18:16:11.278Z",
    "inputs": []
  }],
  "data": {
    "transactions": [{
      "code": "add_proxy",
      "amount": null,
      "raw": "0xa404160100a8aa7e9be09ceb0d3db02ae159bd105253e553bb6c944de7d4c35dfda4ae772c0300000000",
      "signing_payload": "0x160100a8aa7e9be09ceb0d3db02ae159bd105253e553bb6c944de7d4c35dfda4ae772c03000000000048000091880f001b000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423ee143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e00",
      "signed": "0x3d0284004e6f98e193d7ab454d3fad247b17f76d2249df6ac865a4c7e2b599c49392fd33017cdeb40b087efb56cc5b21b05477c1d3c52d0b4cdcee6cc6bea3d64c689f8439d5aa5776d13e4bde360932fe2b2ae6462709eb76959b3bb4f255c70db3a9498400480000160100a8aa7e9be09ceb0d3db02ae159bd105253e553bb6c944de7d4c35dfda4ae772c0300000000",
      "hash": "0x8f95f6d7dd524d97c7e75e22a37ed6e2734e33d168aaa3be6c6f51fe4d2e5cc1",
      "status": null,
      "error": null,
      "signatures": [{
        "account_address": "5DqYk5FDueD5NFxySRx2co5xg5cEChpsPhQTHUB9uAHERRaE",
        "signature": ""
      }],
      "block_time": null,
      "block_number": 25343973,
      "last_valid_block_height": null,
      "proxy": null,
      "inputs": {
        "proxy_account_address": "5FsrYox6CGyZ7rovGAmn17mJyHXf8QFN82KoGYWz6eHnRRXW",
        "proxied_account_address": "5DqYk5FDueD5NFxySRx2co5xg5cEChpsPhQTHUB9uAHERRaE"
      }
    }]
  },
  "network_code": "polkadot",
  "chain_code": "westend",
  "created_at": "2025-03-27T18:03:41.296Z",
  "updated_at": "2025-03-27T18:15:11.111Z"
}
```

# Get Add Staking Proxy Flow Status
To get the current state of the existing flow, send a `GET` request to `/api/v1/flows/[:flow_id]` using the flow ID from the previous step.

### URL
```
GET https://api.figment.io/flows/[:flow_id]
```

### Request
- None

```json
{
    "id": "d04c0129-50b8-4a44-8df0-b52f2d1d6919",
    "operation": "add_proxy",
    "state": "registered",
    "actions": [],
    "data": {
        "proxy_account_address": "5FsrYox6CGyZ7rovGAmn17mJyHXf8QFN82KoGYWz6eHnRRXW",
        "proxied_account_address": "5DqYk5FDueD5NFxySRx2co5xg5cEChpsPhQTHUB9uAHERRaE",
        "add_proxy_transaction": {
            "raw": "0xa404160100a8aa7e9be09ceb0d3db02ae159bd105253e553bb6c944de7d4c35dfda4ae772c0300000000",
            "signing_payload": "0x160100a8aa7e9be09ceb0d3db02ae159bd105253e553bb6c944de7d4c35dfda4ae772c03000000000048000091880f001b000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423ee143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e00",
            "signed": "0x3d0284004e6f98e193d7ab454d3fad247b17f76d2249df6ac865a4c7e2b599c49392fd33017cdeb40b087efb56cc5b21b05477c1d3c52d0b4cdcee6cc6bea3d64c689f8439d5aa5776d13e4bde360932fe2b2ae6462709eb76959b3bb4f255c70db3a9498400480000160100a8aa7e9be09ceb0d3db02ae159bd105253e553bb6c944de7d4c35dfda4ae772c0300000000",
            "hash": "0x8f95f6d7dd524d97c7e75e22a37ed6e2734e33d168aaa3be6c6f51fe4d2e5cc1",
            "status": "confirmed",
            "error": null,
            "signatures": [{
                "account_address": "5DqYk5FDueD5NFxySRx2co5xg5cEChpsPhQTHUB9uAHERRaE",
                "signature": ""
            }],
            "block_time": "2025-03-27T18:15:59.769Z",
            "block_number": 25343976,
            "last_valid_block_height": null,
            "proxy": null
        }
    },
    "protocol": "polkadot",
    "network": "westend",
    "created_at": "2025-03-27T18:03:41.296Z",
    "updated_at": "2025-03-27T18:15:59.780Z"
}
```
