Skip to content

Commit

Permalink
Lint and make nit edits
Browse files Browse the repository at this point in the history
  • Loading branch information
ilikesymmetry committed Nov 8, 2024
1 parent 69f46f0 commit dadb7ad
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
# Client resources
# Client resources

Recommended libraries for handling blockchain and wallet interactions. The example project in the [Quick Start](/guides/spend-permissions/quick-start.mdx) guide uses all three of these.

### Using Viem
[Viem](https://viem.sh/) is a TypeScript interface for Ethereum that provides low-level stateless primitives for interacting with Ethereum.

- **[Getting Started with Viem](https://viem.sh/docs/getting-started.html)**
[Viem](https://viem.sh/) is a TypeScript interface for Ethereum that provides low-level stateless primitives for interacting with Ethereum.

- **[Getting Started with Account Abstraction](https://viem.sh/account-abstraction#getting-started-with-account-abstraction)**
Viem provides support for account abstraction clients, including specific support for Coinbase Smart Wallet and paymasters.
- **[Getting Started with Viem](https://viem.sh/docs/getting-started.html)**

### Using OnchainKit
[OnchainKit](https://onchainkit.xyz/) is a collection of React components and TypeScript utilities that help developers quickly build
onchain applications.
- **[Getting Started with Account Abstraction](https://viem.sh/account-abstraction#getting-started-with-account-abstraction)**
Viem provides support for account abstraction clients, including specific support for Coinbase Smart Wallet and paymasters.

### Using Wagmi

[Wagmi](https://wagmi.sh/) is a collection of React Hooks that facilitate development of blockchain frontends.

- **[Getting Started with Wagmi](https://wagmi.sh/react/getting-started)**
- **[coinbaseWallet](https://wagmi.sh/react/api/connectors/coinbaseWallet)**
- **[Getting Started with Wagmi](https://wagmi.sh/react/getting-started)**
- **[coinbaseWallet](https://wagmi.sh/react/api/connectors/coinbaseWallet)**

### Using OnchainKit

[OnchainKit](https://onchainkit.xyz/) is a collection of React components and TypeScript utilities that help developers quickly build
onchain applications.
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
# `SpendPermissionManager.sol` smart contract

The open-source contracts repository is [here](https://github.com/coinbase/spend-permissions).

### Structs

#### `SpendPermission`

Defines the complete parameters of a spend permission.

| Field | Type | Description |
|-------------|----------|-----------------------------------------------------------------------------|
| `account` | `address`| Smart account this spend permission is valid for. |
| `spender` | `address`| Entity that can spend `account`'s tokens. |
| `token` | `address`| Token address (ERC-7528 native token address or ERC-20 contract). |
| `allowance` | `uint160`| Maximum allowed value to spend within each `period`. |
| `period` | `uint48` | Time duration for resetting used `allowance` on a recurring basis (seconds).|
| `start` | `uint48` | Timestamp this spend permission is valid after (unix seconds). |
| `end` | `uint48` | Timestamp this spend permission is valid until (unix seconds). |
| `salt` | `uint256`| An arbitrary salt to differentiate unique spend permissions with otherwise identical data. |
| `extraData` | `bytes` | Arbitrary data to include in the signature. |
| Field | Type | Description |
| ----------- | --------- | ------------------------------------------------------------------------------------------ |
| `account` | `address` | Smart account this spend permission is valid for. |
| `spender` | `address` | Entity that can spend `account`'s tokens. |
| `token` | `address` | Token address (ERC-7528 native token address or ERC-20 contract). |
| `allowance` | `uint160` | Maximum allowed value to spend within each `period`. |
| `period` | `uint48` | Time duration for resetting used `allowance` on a recurring basis (seconds). |
| `start` | `uint48` | Timestamp this spend permission is valid starting at (unix seconds). |
| `end` | `uint48` | Timestamp this spend permission is valid until (unix seconds). |
| `salt` | `uint256` | An arbitrary salt to differentiate unique spend permissions with otherwise identical data. |
| `extraData` | `bytes` | Arbitrary data to include in the permission. |

#### `PeriodSpend`

Describes the cumulative spend for the current active period.

| Field | Type | Description |
|-------------|----------|-----------------------------------------------------------------------------|
| `start` | `uint48` | Start time of the period (unix seconds). |
| `end` | `uint48` | End time of the period (unix seconds). |
| `spend` | `uint160`| Accumulated spend amount for period. |
| Field | Type | Description |
| ------- | --------- | ---------------------------------------- |
| `start` | `uint48` | Start time of the period (unix seconds). |
| `end` | `uint48` | End time of the period (unix seconds). |
| `spend` | `uint160` | Accumulated spend amount for period. |

---

### Contract functions

#### `approve`

Approve a spend permission via a direct call from the `account`. Only callable by the `account` specified in the spend permission.
Expand All @@ -55,7 +59,7 @@ function approveWithSignature(SpendPermission calldata spendPermission, bytes ca
Spend tokens using a spend permission, transferring them from the `account` to the `spender`. Only callable by the `spender` specified in the permission.

```solidity
function spend(SpendPermission memory spendPermission, uint160 value) external requireSender(spendPermission.spender);
function spend(SpendPermission memory spendPermission, uint160 value) external;
```

---
Expand All @@ -65,7 +69,7 @@ function spend(SpendPermission memory spendPermission, uint160 value) external r
Revoke a spend permission, permanently disabling its use. Only callable by the `account` owner specified in the spend permission.

```solidity
function revoke(SpendPermission calldata spendPermission) external requireSender(spendPermission.account);
function revoke(SpendPermission calldata spendPermission) external;
```

---
Expand Down Expand Up @@ -93,8 +97,9 @@ function isApproved(SpendPermission memory spendPermission) public view returns
#### `getCurrentPeriod`

Retrieve the `start`, `end`, and accumulated `spend` for the current period of a spend permission.
Reverts if the current time is outside the valid time range of the permission, but does not validate whether the
Reverts if the current time is outside the valid time range of the permission, but does not validate whether the
spend permission has been approved or revoked.

```solidity
function getCurrentPeriod(SpendPermission memory spendPermission) public view returns (PeriodSpend memory);
```
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
## Coinbase Wallet API

### `wallet_fetchPermissions`

A utility API endpoint for recalling permissions previously granted for a specific user.
Excludes any permissions that have been revoked or are expired.
Excludes permissions that have expired or been revoked.

#### Schema

**Endpoint:** `https://chain-proxy.wallet.coinbase.com?targetName=base-sepolia`.

```typescript
type FetchPermissionsRequest = {
chainId: string; // uint256, hex formatted
chainId: string; // hex, uint256
account: string; // address
spender: string; // address
pageOptions?: {
Expand All @@ -24,22 +28,20 @@ type FetchPermissionsResult = {
}
}

type PageDescription =

type FetchPermissionsResultItem = {
createdAt: number; // UTC timestamp for when the permission was granted
permissionHash: string;
signature: string;
permissionHash: string; // hex
signature: string; // hex
permission: {
account: string; // address
spender: string; // address
token: string; // address
allowance: string; // base 10 numeric string
period: number; // unix time, seconds
start: number; // unix time, seconds
end: number; // unix time, seconds
period: number; // unix seconds
start: number; // unix seconds
end: number; // unix seconds
salt: string; // base 10 numeric string
extraData: string // hex formatted bytes, i.e. "0x" for empty data
extraData: string // hex
};
}
```

0 comments on commit dadb7ad

Please sign in to comment.