Skip to content

Commit

Permalink
conner review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
amiecorso committed Nov 7, 2024
1 parent ab5365c commit ee70bd0
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 277 deletions.
276 changes: 0 additions & 276 deletions docs/pages/guides/spend-permissions/api-reference.mdx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Client resources

### 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)**

- **[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 OnchainKit
[OnchainKit](https://onchainkit.xyz/) is a collection of React components and TypeScript utilities that help developers quickly build
onchain applications.

### 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)**
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# `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. |

#### `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. |

---

### Contract functions
#### `approve`

Approve a spend permission via a direct call from the `account`. Only callable by the `account` specified in the spend permission.

```solidity
function approve(SpendPermission calldata spendPermission) external;
```

---

#### `approveWithSignature`

Approve a spend permission via a signature from the `account` owner. Compatible with [ERC-6492](https://eips.ethereum.org/EIPS/eip-6492) signatures for automatic account creation if needed.

```solidity
function approveWithSignature(SpendPermission calldata spendPermission, bytes calldata signature) external;
```

---

#### `spend`

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);
```

---

#### `revoke`

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);
```

---

#### `getHash`

Generate a hash of a `SpendPermission` struct for signing, in accordance with [EIP-712](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md).

```solidity
function getHash(SpendPermission memory spendPermission) public view returns (bytes32);
```

---

#### `isApproved`

Check if a spend permission is approved and not revoked.

```solidity
function isApproved(SpendPermission memory spendPermission) public view returns (bool);
```

---

#### `getCurrentPeriod`

Retrieve the `start`, `end`, and accumulated `spend` for the current period of a spend permission.

```solidity
function getCurrentPeriod(SpendPermission memory spendPermission) public view returns (PeriodSpend memory);
```
Loading

0 comments on commit ee70bd0

Please sign in to comment.