Skip to content
Merged
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
84 changes: 45 additions & 39 deletions docs/guides/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The following operations will return errors if the user has any channel with non
- **Submit App State** (with deposit intent): Rejected if attempting to deposit
- **Create App Session** (with allocations): Rejected if attempting to allocate

The error is returned has the following format: `operation denied: non-zero allocation in <count> channel(s) detected owned by wallet <address>"`
The returned error has the following format: `operation denied: non-zero allocation in <count> channel(s) detected owned by wallet <address>"`

### Nitrolite SDK

Expand Down Expand Up @@ -142,52 +142,58 @@ await client.resizeChannel({

#### Resize correctly

Use `resize_amount` and `allocate_amount` with correct sign convention (`resize_amount = -allocate_amount`) and help users with non-zero channel balances migrate by resizing to zero or reopening channels:
Channel resizing must be negotiated with the ClearNode through WebSocket. Use `resize_amount` and `allocate_amount` with correct sign convention (`resize_amount = -allocate_amount`) and help users with non-zero channel balances migrate by resizing to zero or reopening channels.

<Tabs>
<TabItem value="deposit" label="Deposit to Unified Balance">
Channel resize can be requested as follows:

```typescript
// Deposit from custody ledger to unified balance
await client.resizeChannel({
channel_id: channelId,
resize_amount: BigInt(50), // Positive = deposit to channel
allocate_amount: BigInt(-50), // Negative = deposit to unified balance
});
```
```typescript
const resizeMessage = await createResizeChannelMessage(messageSigner, {
channel_id: channelId,
resize_amount: BigInt(50), // Positive = deposit to channel, negative = withdraw from channel to custody ledger
allocate_amount: BigInt(-50), // Negative = deposit to unified balance, negative = withdraw from unified balance to channel
funds_destination: walletAddress,
});

</TabItem>
<TabItem value="withdraw" label="Withdraw from Unified Balance">
const resizeResponse = {}; // send the message and wait for Clearnode's response

```typescript
// Withdraw from unified balance to custody ledger
await client.resizeChannel({
channel_id: channelId,
resize_amount: BigInt(-100), // Negative = withdraw from channel
allocate_amount: BigInt(100), // Positive = withdraw from unified balance
});
```
const { params: resizeResponseParams } = parseResizeChannelResponse(resizeResponse);
const resizeParams = {
resizeState: {
channelId,
...resizeResponseParams.state,
serverSignature: resizeResponseParams.serverSignature,
data: resizeResponseParams.state.stateData as Hex,
version: BigInt(resizeResponseParams.state.version),
},
// `previousState` is either initial or previous resizing state, depending on which has higher version number
// can be obtained with `await (client.getChannelData(channelId)).lastValidState`
proofStates: [previousState],
}

</TabItem>
<TabItem value="migrate" label="Migrate Legacy Channels">
const {txHash} = await client.resizeChannel(resizeParams);
```

```typescript
// Check and migrate channels with non-zero amounts
const channels = await client.getChannels();

for (const channel of channels) {
if (channel.amount > 0) {
// Must empty channel to enable transfers/app operations
await client.resizeChannel({
channel_id: channel.channelId,
allocate_amount: -channel.amount,
});
}
Here is how you can migrate your channels:

```typescript
// Check and migrate channels with non-zero amounts
const channels = await client.getOpenChannels();

for (const channel of channels) {
if (channel.amount > 0) {
// Must empty channel to enable transfers/app operations
const resizeMessage = await createResizeChannelMessage(messageSigner, {
channel_id: channel.channelId,
resize_amount: BigInt(0),
allocate_amount: -BigInt(channel.amount),
funds_destination: walletAddress,
});

// perform the resize as shown above
}
```
}
```

</TabItem>
</Tabs>

**Critical:** Operations blocked when any channel has non-zero amount:
- Off-chain transfers
Expand Down