Skip to content

Commit 41dd41c

Browse files
committed
Merge branch 'main' into proxies
2 parents 7b958cd + 605fac7 commit 41dd41c

File tree

6 files changed

+673
-20
lines changed

6 files changed

+673
-20
lines changed

docs/btcli/btcli.md

Lines changed: 233 additions & 17 deletions
Large diffs are not rendered by default.

docs/errors/subtensor.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,10 @@ Symbol does not exist.
496496

497497
Symbol already in use.
498498

499+
### `BadOrigin`
500+
501+
Wallet not authorized. Ensure that the account has the correct root or subnet owner permissions.
502+
499503
### `InvalidValue`
500504

501505
Generic error for out-of-range parameter value

docs/keys/schedule-coldkey-swap.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ The schedule coldkey swap feature works as follows:
2020

2121
- The schedule coldkey swap feature enables you to schedule the swapping of source coldkey to a destination coldkey. If you feel your existing coldkey is potentially compromised, then use this feature to schedule a swap to a destination coldkey.
2222
- When you use this feature, it will not immediately swap your coldkeys and swap your TAO funds from the source coldkey to the destination coldkey. It will only schedule the swap event.
23-
- All scheduled coldkey swaps will be executed on-chain. **Your scheduled coldkey swap will execute on the mainnet exactly 5 days after you successfully scheduled the coldkey swap using the method described in this document.**
24-
- The source coldkey you used in this method will be locked when you schedule the swap. After the 5-day period is elapsed your original coldkey will be unlocked entirely.
23+
- All scheduled coldkey swaps will be executed on-chain. **Your scheduled coldkey swap will execute on the mainnet 7200 blocks (approximately 24 hours) after you successfully scheduled the coldkey swap using the method described in this document.**
24+
- The source coldkey you used in this method will be locked when you schedule the swap. After the 7200-block period is elapsed your original coldkey will be unlocked entirely.
2525
- **Cost**: The cost of this coldkey swap transaction is 0.1 TAO. This must be available in your source coldkey.
2626
- Any subnet ownership from your source coldkey will move to the destination coldkey.
2727
- The delegated stake will be transferred from your source coldkey to the destination coldkey.
@@ -99,4 +99,4 @@ Scroll down to the bottom of the page and click on the **Submit Transaction** bu
9999

100100
## Verify
101101

102-
Your scheduled coldkey swap will execute on the mainnet 5 days after you successfully scheduled the coldkey swap using the above method. Check your destination coldkey after 5 days to verify.
102+
Your scheduled coldkey swap will execute on the mainnet 7200 blocks after you successfully scheduled the coldkey swap using the above method. Check your destination coldkey after approximately 24 hours to verify.
Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
---
2+
title: "Create a Subnet with a Crowdloan"
3+
---
4+
5+
# Create a Subnet with a Crowdloan
6+
7+
This page describes creating a subnet via **crowdloan** on a locally deployed Bittensor chain. We will use the Polkadot‑JS web app to submit extrinsics.
8+
9+
See also [Crowdloans Overview](./index.md)
10+
11+
The following steps will take us through the lifecycle of a subnet creation crowdloan:
12+
13+
- First, we will **create** a crowdloan for a subnet. This is a special contract that will conditionally create the subnet if enough funds are raised (this threshold is called a crowdloan's **cap**).
14+
- Next, we will **contribute** enough funds for the crowdloan to reach its cap.
15+
- Next we must **finalize** the crowdloan, which executes the action wrapped inside the crowdloan—the creation of the subnet.
16+
- Finally, we will verify the successful creation of the subnet by starting its emissions and observing the flow of liquidity to validator and creator hotkeys.
17+
18+
## Prerequisites
19+
20+
- A locally running subtensor development chain. For more information, see [run a local Bittensor blockchain instance](../../local-build/deploy.md).
21+
- [Polkadot‑JS browser app](https://polkadot.js.org/apps/?#/explorer) and [Polkadot‑JS browser extension](https://chrome.google.com/webstore/detail/polkadot%7Bjs%7D-extension/mopnmbcafieddcagagdcbnhejhlodfdd) installed.
22+
- An accessible 'Alice' wallet (see: [Provision Wallets for Local Deploy](../../local-build/provision-wallets))
23+
24+
## Step 1: Connect Polkadot‑JS to your local chain
25+
26+
1. Open the Polkadot‑JS app.
27+
2. In the network selector, choose Development → custom endpoint `ws://127.0.0.1:9944`.
28+
3. Confirm your local chain metadata loads and your test accounts appear in the Accounts tab. To do this, see [create and import accounts to the Polkadot-JS extension](../../keys/multisig.md#create-and-import-3-coldkey-pairs-accounts-in-the-polkadot-js-browser-extension).
29+
30+
:::tip
31+
If the web app does not connect to your local chain, your browser’s privacy or security settings may be blocking it. Try adjusting those settings and reconnecting.
32+
:::
33+
34+
## Step 2: Generate call hash
35+
36+
Before creating the crowdloan, you must first generate the hash that registers the subnet and creates a dedicated proxy for the designated beneficiary.
37+
To begin:
38+
39+
1. Go to **Developer****Extrinsics**.
40+
2. Under “**using the selected account**”, pick the crowdloan "`creator`" account.
41+
3. Under “**submit the following extrinsic**”, choose module `subtensorModule`, call `registerLeasedNetwork(emissionsShare, endBlock)`.
42+
4. Fill the parameters:
43+
44+
- `emissionsShare`: choose a percentage, e.g, 30.
45+
- `endBlock`: leave as none.
46+
47+
5. Copy the hex code shown in the **encoded call data** field. You will use this to create the crowdloan in the next step.
48+
49+
:::info
50+
Do not submit the transaction after entering the parameters. Only copy the encoded call data once all parameters are provided.
51+
:::
52+
53+
## Step 3: Create a crowdloan
54+
55+
We will create a campaign whose purpose is to register a leased subnet on finalize.
56+
57+
1. Go to **Developer****Extrinsics**.
58+
2. Under “**using the selected account**”, pick the crowdloan "`creator`" account.
59+
3. Under “**submit the following extrinsic**”, choose module `crowdloan`, call `create`.
60+
4. Fill the parameters:
61+
62+
- `deposit`: choose an amount (e.g., `10,000,000,000` = 10 TAO on default dev config)
63+
- `min_contribution`: e.g., `100,000,000` (0.1 TAO)
64+
- `cap`: e.g., `2,000,000,000,000` (2000 TAO)
65+
- `end`: pick a block height in the near future (e.g., current + 5000)
66+
- `call`: put the hex code of the encoded call data saved from the previous step.
67+
- `target_address`: leave as **None**.
68+
69+
:::info
70+
71+
- Set the `cap` value higher than the projected subnet lock cost plus proxy deposit (and a small fee buffer). On most dev setups the baseline lock cost is 1,000 TAO (1,000,000,000,000 RAO). If `cap` equals the lock cost exactly, the lease coldkey may lack enough to pay proxy deposits and finalize can fail with insufficient balance.
72+
- If your local subtensor node uses non-fast blocks, the minimum duration for a crowdloan is one week (≈ 50,400 blocks). Therefore, the `end` value must be set at least 50,400 blocks after the current block. This limitation also applies on testnet and mainnet.
73+
:::
74+
75+
5. Click **Submit Transaction** and sign with the `creator` account.
76+
77+
### Get the crowdloan ID
78+
79+
Crowdloan IDs are allocated sequentially, starting from `0`, with each new crowdloan assigned the next incremental ID. There is no extrinsic to list created crowdloans. Therefore, to check the identity of crowdloans created, you must use one of these methods.
80+
81+
- **From Events**:
82+
83+
1. Navigate to the **block explorer** after submitting the crowdload transaction.
84+
2. In the **Explorer** tab, find the block in which the transaction occured.
85+
3. In the **Events** panel, locate the `crowdloan.create` extrinsic. The `crowdloan.Created` event payload includes `crowdloanId` that represents the ID of the crowdloan.
86+
87+
- **From storage**:
88+
89+
1. From the **Developer** dropdown, navigate to **Chain state****Storage**.
90+
2. Click the **selected state query** menu and select `crowdloan.nextCrowdloanId`.
91+
3. Click the **+** icon to run the query.
92+
93+
:::tip
94+
This query returns the ID assigned to the next crowdloan that will be created. Subtract 1 from the returned value to determine the total number of crowdloans that currently exist.
95+
:::
96+
97+
- **From the JS console**:
98+
1. From the **Developer** dropdown, navigate to **Javascript**.
99+
2. Next, paste the following code block in the editor and run:
100+
101+
```javascript
102+
// List all existing crowdloan ids
103+
const keys = await api.query.crowdloan.crowdloans.keys();
104+
console.log(keys.map((k) => k.args[0].toNumber()));
105+
```
106+
107+
## Step 4: Contribute to the crowdloan
108+
109+
All contributions must occur before the defined `end` block and will be clipped to the `cap` value provided.
110+
111+
To contribute to the crowdloan, repeat the following steps for each contributor account:
112+
113+
1. From the **Developer** dropdown, navigate to **Extrinsics**
114+
2. Under “**using the selected account**”, select the crowdloan "contributor(s)" account.
115+
3. Under “**submit the following extrinsic**”, choose module `crowdloan`, call `contribute (crowdloan_id, amount)`.
116+
4. Provide the `crowdloan_id` (typically 0 on a fresh chain) and an amount.
117+
5. Submit and sign.
118+
119+
:::info
120+
121+
The crowdloan cap is the maximum total raise. If a contribution would push the total above this cap, the contribution is clipped to fit the remaining available amount. Once the cap is reached, any further contributions are rejected and a `crowdloan.CapRaised` event is triggered.
122+
:::
123+
124+
### Verify crowdloan contributions
125+
126+
To verify crowdload contributions:
127+
128+
- **From Events**:
129+
130+
1. Navigate to the **block explorer** after contributing to the crowdload.
131+
2. In the **Explorer** tab, find the block in which the transaction occured.
132+
3. In the **Events** panel, locate the `crowdloan.contribute` extrinsic. The `crowdloan.Contributed` event payload contains the `crowdloanId`, the contributing account, and amount contributed.
133+
134+
- **From storage**:
135+
136+
1. From the **Developer** dropdown, navigate to **Chain state****Storage**.
137+
2. Click the **selected state query** menu and select one of the following:
138+
139+
- `crowdloan.Crowdloans(crowdloan_id)` to check details of the crowdloan
140+
- `crowdloan.Contributions(crowdloan_id, contributor)` to check contributions by an account.
141+
142+
3. Click the **+** icon to run the query.
143+
144+
## Step 5: Finalize the crowdloan
145+
146+
The crowdload can be finalized by the creator when the end block has passed and the cap has been fully raised (`raised == cap`).
147+
148+
1. Wait for the chain to reach the `end` block.
149+
2. From the **Developer** dropdown, go to **Extrinsics**.
150+
3. Under **using the selected account**, select the crowdloan creator account.
151+
4. Select `crowdloan.finalize(crowdloan_id)` and put the ID of the crowdload.
152+
5. Submit and sign.
153+
154+
<details>
155+
<summary><strong>Show Event Output</strong></summary>
156+
```
157+
system.ExtrinsicSuccess
158+
balances.Withdraw (x2)
159+
system.NewAccount (x2)
160+
balances.Endowed
161+
balances.Transfer (x2)
162+
subtensorModule.RegistrationAllowed
163+
subtensorModule.MaxAllowedUidsSet
164+
subtensorModule.MaxAllowedValidatorsSet
165+
subtensorModule.MinAllowedWeightSet
166+
subtensorModule.MaxWeightLimitSet
167+
subtensorModule.AdjustmentIntervalSet
168+
subtensorModule.RegistrationPerIntervalSet
169+
subtensorModule.AdjustmentAlphaSet
170+
subtensorModule.ImmunityPeriodSet
171+
subtensorModule.MinDifficultySet
172+
subtensorModule.MaxDifficultySet
173+
subtensorModule.NetworkAdded
174+
balances.Reserved
175+
proxy.ProxyAdded
176+
subtensorModule.SubnetLeaseCreated
177+
crowdloan.Finalized
178+
balances.Deposit
179+
transactionPayment.TransactionFeePaid
180+
extrinsic event
181+
```
182+
</details>
183+
184+
:::info
185+
186+
- Even if the `cap` has been raised, the crowdloan cannot be finalized before the `end` block. Finalizing before the contribution period ends fails with a `ContributionPeriodNotEnded` event.
187+
- If `target_address` was provided, the raised amount is transferred there.
188+
- The stored `subtensor.register_leased_network` call executes with creator origin, and the subnet lease is created.
189+
- The created subnet lease includes the coldkey and hotkey of the proxy wallet that manages the subnet. See [Get the lease coldkey](#get-the-lease-coldkey).
190+
:::
191+
192+
### Verify the leased subnet
193+
194+
Finalizing the crowdloan registers a new subnet and creates a dedicated proxy for the designated beneficiary. Use one of the following methods to verify the creation of the leased subnet:
195+
196+
- **Using BTCLI**:
197+
198+
You can verify the creation of the new subnet by running the following command in your terminal:
199+
200+
```sh
201+
btcli subnets list --network local
202+
```
203+
204+
This command lists all created subnets on the chain. Notice the addition of a new subnet among the listed subnets—netuid `2` in the following output.
205+
206+
<details>
207+
<summary><strong>Show Sample Output</strong></summary>
208+
209+
```console
210+
Using the specified network local from config
211+
[15:49:40] Warning: Verify your local subtensor is running on port 9944. subtensor_interface.py:89
212+
213+
Subnets
214+
Network: local
215+
216+
217+
┃ ┃ Price ┃ Market Cap ┃ ┃ ┃ ┃ ┃
218+
Netuid ┃ Name ┃ (Τ_in/α_in) ┃ (α * Price) ┃ Emission (Τ) ┃ P (Τ_in, α_in) ┃ Stake (α_out) ┃ Supply (α) ┃ Tempo (k/n)
219+
━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━
220+
0 │ τ root │ 1.0000 τ/Τ │ τ 0.00 │ τ 0.0000 │ -, - │ Τ 0.00 │ 0.00 Τ /21M │ -/-
221+
2 │ β omron │ 0.0000 τ/β │ τ 0.00 │ τ 0.0000 │ τ 1.00k, 1.00k β │ 0.00 β │ 1.00k β /21M │ 3/10
222+
1 │ α apex │ 0.0000 τ/α │ τ 0.00 │ τ 0.0000 │ τ 10.00, 10.00 α │ 1.00 α │ 11.00 α /21M │ 28/100
223+
────────┼───────────┼─────────────┼─────────────┼──────────────┼────────────────────────┼───────────────┼──────────────┼─────────────
224+
4 │ │ τ 0.0 │ │ τ 0.0 │ τ 2.01k/20.93k (9.60%) │ │ │
225+
226+
```
227+
228+
</details>
229+
230+
## Step 6: Start the leased subnet (via proxy)
231+
232+
Before starting the subnet, you must first get the address of the proxy wallet specified in the subnet lease, as this wallet controls the subnet.
233+
234+
#### **Get the lease coldkey**
235+
236+
1. From the **Developer** dropdown, navigate to **Chain state****Storage**.
237+
2. Click the **selected state query** menu and select `subtensorModule.SubnetLeases(lease_id)` to display details of the subnet lease, including the beneficiary, emission share, end block, lease coldkey and hotkey, netuid, and creation cost.
238+
3. Click the **+** icon to run the query.
239+
4. Copy the value of the `lease.coldkey` in the response. You can add the lease coldkey to the address book on the Polkadot.js web app so that it's selectable in the UI.
240+
241+
:::tip
242+
243+
- In your local environment, the `lease_id` would be the same as the ID of the crowdloan created. You can confirm the `lease_id` by examining the block where the subnet lease was created for a `subtensorModule.SubnetLeaseCreated` event.
244+
245+
:::
246+
247+
Next, follow the following steps to start the subnet:
248+
249+
1. Go to **Developer****Extrinsics**.
250+
2. Under “**using the selected account**”, pick the crowdloan "`creator`" account.
251+
3. Under “**submit the following extrinsic**”, choose module `proxy`, call `proxy(real, forceProxyType, call)`.
252+
4. Fill the parameters:
253+
254+
- `real`: enter the `lease.coldkey` gotten from the previous query.
255+
- `forceProxyType`: click the toggle and then choose the `SubnetLeaseBeneficiary`option in the dropdown.
256+
- `call`: choose `subtensorModule.start_call` and then enter the netuid of the subnet you want to start.
257+
- Submit and sign.
258+
259+
## Observe dividends distribution
260+
261+
Emissions accrue in Alpha (subnet share units), but are distributed in TAO. On distribution, the contributors' alpha is unstaked/swapped to TAO using the subnet pool; if swap/unstake cannot proceed (liquidity/price), the alpha is accumulated for later.
262+
263+
Owner emissions are periodically split among contributors and the beneficiary, but only when all of these are true:
264+
265+
- The subnet is leased and active (lease has not ended).
266+
- A coinbase cycle paid an owner cut to the subnet owner for the given `netuid`.
267+
- Current block is an exact multiple of `LeaseDividendsDistributionInterval` (check in Constants).
268+
- There is sufficient liquidity to unstake the contributors’ cut from the subnet at or above the minimum swap price.
269+
270+
Balances credited go to each contributor’s coldkey and the beneficiary’s coldkey. You can observe changes by querying balances over time.
271+
272+
## Alternative path: Refund and dissolve
273+
274+
If the cap is not reached by `end`:
275+
276+
1. Anyone can call `crowdloan.refund(crowdloan_id)` repeatedly until all contributors (except the creator) are refunded (batched per call).
277+
2. After refunds complete (only the creator’s deposit remains), the `creator` can call `crowdloan.dissolve(crowdloan_id)` to clean up and recover the deposit.
278+
279+
### Optional: Withdraw
280+
281+
Before finalization:
282+
283+
- Any contributor can `crowdloan.withdraw(crowdloan_id)` to recover their contribution.
284+
- The creator can only withdraw amounts above the kept deposit; the deposit itself remains until refund/dissolve.
285+
286+
## Troubleshooting
287+
288+
- Call fails with `InvalidCrowdloadId`
289+
- Ensure that the crowdloan ID exists.
290+
- Call fails with `InvalidOrigin`
291+
- Ensure that the selected account that is responsible for signing the transaction.
292+
- Call fails with `BlockDurationTooShort`
293+
- Ensure that the crowdloan `end` is set at least one week away—~50,400 blocks.
294+
- Call fails with `BlockDurationTooLong`
295+
- Ensure that the crowdloan `end` is set between a week to 2 months away.
296+
- Contribution call fails with `ContributionPeriodEnded`
297+
- Extend the `end` value on the crowdloan using the `crowdloan.updateEnd` extrinsic.
298+
- Finalize fails with `CapNotRaised`
299+
- Ensure total `raised` equals `cap`. Add contributions or adjust `cap` via `update_cap` (creator‑only) before `finalize`.
300+
- Finalize fails with `ContributionPeriodNotEnded`
301+
- Wait until the `end` block is reached.
302+
- Finalize fails with `CallUnavailable`
303+
- Ensure the nested call was supplied during `create`. The pallet stores it as a preimage; if unavailable, it errors and drops the reference.
304+
- Refund does nothing
305+
- Refunds only after `end` and only for non‑finalized campaigns. It processes up to `RefundContributorsLimit` contributors per call.

0 commit comments

Comments
 (0)