Skip to content

Commit

Permalink
Update /magic-spend/architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlovdog committed Nov 6, 2024
1 parent d11ff50 commit 2a5fdcb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
26 changes: 17 additions & 9 deletions docs/pages/infra/magic-spend/architecture.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,39 @@ MagicSpend++ is a protocol that allows users to spend their funds on any chain t
### `Allowance` message

```solidity
/// @notice Helper struct that represents an allowance for a specific asset.
struct AssetAllowance {
/// @dev Asset that can be claimed.
address asset;
/// @dev Token that can be claimed.
address token;
/// @dev The amount to claim.
uint128 amount;
/// @dev The chain id of the network, where the claim will be made.
uint128 chainId;
}
/// @notice Helper struct that represents an allowance.
/// @dev signed by the user it allows Pimlico to claim part of user's stake from the `MagicSpendStakeManager` contract
/// @dev on one or many chains.
struct Allowance {
/// @dev Address which stake is allowed to be claimed.
address account;
/// @dev List of allowances, one allowance per chain.
AssetAllowance[] allowances;
/// @dev List of assets, allowed to be claimed.
/// @dev One allowance per asset, where asset is the combination of (token,chainId)
AssetAllowance[] assets;
/// @dev The time in which the allowance is valid until.
uint48 validUntil;
/// @dev The time in which the allowance is valid after.
uint48 validAfter;
/// @dev The salt of the allowance.
uint48 salt;
/// @dev Address which allowed to request withdrawals on behalf of this allowance.
/// @dev Signer which is allowed to request withdrawals on behalf of this allowance.
address operator;
}
```

`Allowance` is a message that user signs and sends to Pimlico. It contains the details of the stake, such as the asset, amount, chain id, etc. Pimlico can claim the user's stake only if the user provided a signed `Allowance` message.

Each `Allowance` can have many `AssetAllowance`, where each `AssetAllowance` represents an allowance on a separate chain. It allows users to provide parts of their stakes on different chains in a single request.
Each `Allowance` can have many `AssetAllowance`, where each `AssetAllowance` represents a unique combination of `(AssetAllowance.token,AssetAllowance.chainId)`. It allows users to provide parts of their stakes on different chains and tokens in a single request.

### Upgradability

Expand All @@ -68,12 +73,14 @@ struct Call {
bytes data;
}
/// @notice This struct represents a withdrawal request.
/// @dev signed by the signer it allows to withdraw funds from the `MagicSpendWithdrawalManager` contract
struct Withdrawal {
/// @dev Asset that will be withdrawn.
address asset;
/// @dev Token that will be withdrawn.
address token;
/// @dev The requested amount to withdraw.
uint128 amount;
/// @dev Chain id of the network, where the withdrawal will be made.
/// @dev Chain id of the network, where the withdrawal will be executed.
uint128 chainId;
/// @dev Address that will receive the funds.
address recipient;
Expand All @@ -88,6 +95,7 @@ struct Withdrawal {
/// @dev The salt of the withdrawal.
uint48 salt;
}
```

`Withdrawal` is a message that Pimlico signs and sends to user. It contains the details of the withdrawal, such as the asset, amount, recipient, chain id, etc.
Expand Down
10 changes: 5 additions & 5 deletions docs/pages/infra/magic-spend/staking.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Using the MagicSpend++ requires having one or many stakes on any connected EVM c

## Adding stake

To add a stake user has to send a transaction to the `MagicSpendStakeManager` contract with the `addStake` function call. The function has three parameters: `asset`, `amount`, and `unstakeDelaySec`. The `asset` parameter is the address of the token to stake, `amount` is the amount of tokens to stake, and `unstakeDelaySec` is the time in seconds after which the stake can be removed.
To add a stake user has to send a transaction to the `MagicSpendStakeManager` contract with the `addStake` function call. The function has three parameters: `token`, `amount`, and `unstakeDelaySec`. The `token` parameter is the address of the token to stake, `amount` is the amount of tokens to stake, and `unstakeDelaySec` is the time in seconds after which the stake can be removed.

:::tip[Tip]
For now, the only supported asset is ETH. It's represented by the `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE` address.
For now, the only supported token is ETH. It's represented by the `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE` address.
:::

```bash
Expand All @@ -16,15 +16,15 @@ cast send 0x023Cdb354f655DED93Df8F5C220Cb43F82194D92 "addStake(address,uint128,u

### Choosing the unstake delay

We recommend setting the unstake delay to 3 days (`259200` seconds). The value can't be higher than 5 days, so the maximum delay is `432000` seconds. For each asset, after stake added the first time, the delay can't be changed. If the user wants to change the delay, they have to remove the stake and add it again.
We recommend setting the unstake delay to 3 days (`259200` seconds). The value can't be higher than 5 days, so the maximum delay is `432000` seconds. For each token, after stake added the first time, the delay can't be changed. If the user wants to change the delay, they have to remove the stake and add it again.

## Removing stake

To remove stake user has to send two transactions: one to unlock the stake and another to remove it.

### Unlocking stake

To unlock the stake user has to send a transaction to the `MagicSpendStakeManager` contract with the `unlockStake` function call. The function has one parameter: `asset` which is the address of the token to unlock.
To unlock the stake user has to send a transaction to the `MagicSpendStakeManager` contract with the `unlockStake` function call. The function has one parameter: `token` which is the address of the token to unlock.

Unlocking stake starts the unstake delay timer. After the delay is over the stake can be removed.

Expand All @@ -34,7 +34,7 @@ cast send 0x023Cdb354f655DED93Df8F5C220Cb43F82194D92 "unlockStake(address)" 0xEe

### Removing stake

To remove the stake user has to send a transaction to the `MagicSpendStakeManager` contract with the `withdrawStake` function call. The function has two parameters: `asset` which is the address of the token to remove and `recipient` which is the address to send the tokens to.
To remove the stake user has to send a transaction to the `MagicSpendStakeManager` contract with the `withdrawStake` function call. The function has two parameters: `token` which is the address of the token to remove and `recipient` which is the address to send the tokens to.

```bash
cast send 0x023Cdb354f655DED93Df8F5C220Cb43F82194D92 "withdrawStake(address,address)" 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE,vitalik.eth --private-key 0x... --rpc-url https://11155111.rpc.thirdweb.com/
Expand Down

0 comments on commit 2a5fdcb

Please sign in to comment.