> ## Documentation Index
> Fetch the complete documentation index at: https://daehan-base.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Spend Permissions

> Spend Permissions 온체인 컨트랙트 구조와 주요 필드를 설명합니다.

export const GithubRepoCard = ({title, githubUrl}) => {
  return <a href={githubUrl} target="_blank" rel="noopener noreferrer" className="mb-4 flex items-center rounded-lg bg-zinc-900 p-4 text-white transition-all hover:bg-zinc-800">
      <div className="flex w-full items-center gap-3">
        <svg height="24" width="24" className="flex-shrink-0 dark:fill-white" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
          <path fill="currentColor" fillRule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z" />
        </svg>

        <div className="flex min-w-0 flex-grow flex-col">
          <span className="truncate text-base font-medium">{title}</span>
          <span className="truncate text-xs text-zinc-400">{githubUrl}</span>
        </div>

        <svg className="h-5 w-5 flex-shrink-0 text-zinc-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
          <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
        </svg>
      </div>
    </a>;
};

아래 버튼을 클릭하면 오픈소스 컨트랙트 저장소를 확인할 수 있습니다.

<GithubRepoCard title="Spend Permissions" githubUrl="https://github.com/coinbase/spend-permissions" />

### 구조체

#### `SpendPermission`

지출 권한의 전체 파라미터를 정의합니다.

<Warning>
  `SpendPermission` 구조체의 필드는 아래 정의된 순서를 정확히 따라야 합니다.
</Warning>

| 필드          | 타입        | 설명                                                      |
| ----------- | --------- | ------------------------------------------------------- |
| `account`   | `address` | 이 지출 권한이 유효한 스마트 계정입니다.                                 |
| `spender`   | `address` | `account`의 토큰을 지출할 수 있는 주체입니다.                          |
| `token`     | `address` | 토큰 주소입니다. ERC-7528 네이티브 토큰 주소 또는 ERC-20 컨트랙트 주소를 사용합니다. |
| `allowance` | `uint160` | 각 `period` 동안 지출할 수 있는 최대 한도입니다.                        |
| `period`    | `uint48`  | 사용된 `allowance`를 주기적으로 초기화하는 시간 길이입니다. 단위는 초입니다.        |
| `start`     | `uint48`  | 이 지출 권한이 유효해지는 시작 시각입니다. Unix 초 단위를 사용합니다.              |
| `end`       | `uint48`  | 이 지출 권한이 유효한 종료 시각입니다. Unix 초 단위를 사용합니다.                |
| `salt`      | `uint256` | 나머지 데이터가 같더라도 서로 다른 지출 권한을 구분하기 위한 임의 salt 값입니다.        |
| `extraData` | `bytes`   | 권한에 포함할 임의 데이터입니다.                                      |

#### `PeriodSpend`

현재 활성 기간 동안 누적된 지출량을 설명합니다.

| 필드      | 타입        | 설명                             |
| ------- | --------- | ------------------------------ |
| `start` | `uint48`  | 기간 시작 시각입니다. Unix 초 단위를 사용합니다. |
| `end`   | `uint48`  | 기간 종료 시각입니다. Unix 초 단위를 사용합니다. |
| `spend` | `uint160` | 해당 기간 동안 누적된 지출 금액입니다.         |

***

### 컨트랙트 함수

#### `approve`

`account`에서 직접 호출해 지출 권한을 승인합니다. `SpendPermission`에 지정된 `account`만 호출할 수 있습니다.

```solidity theme={null}
function approve(SpendPermission calldata spendPermission) external;
```

***

#### `approveWithSignature`

`account` 소유자의 서명으로 지출 권한을 승인합니다. 필요 시 자동 계정 생성을 지원하는 [ERC-6492](https://eips.ethereum.org/EIPS/eip-6492) 서명과 호환됩니다.

```solidity theme={null}
function approveWithSignature(SpendPermission calldata spendPermission, bytes calldata signature) external;
```

***

#### `spend`

지출 권한을 사용해 `account`에서 `spender`로 토큰을 전송합니다. 권한에 지정된 `spender`만 호출할 수 있습니다.

```solidity theme={null}
function spend(SpendPermission memory spendPermission, uint160 value) external;
```

***

#### `revoke`

지출 권한을 영구적으로 비활성화합니다. 권한에 지정된 `account`만 호출할 수 있습니다.

```solidity theme={null}
function revoke(SpendPermission calldata spendPermission) external;
```

***

#### `revokeAsSpender`

지출 권한을 영구적으로 비활성화합니다. 권한에 지정된 `spender`만 호출할 수 있습니다.

```solidity theme={null}
function revokeAsSpender(SpendPermission calldata spendPermission) external;
```

***

#### `getHash`

[EIP-712](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md)에 따라 서명용 `SpendPermission` 구조체 해시를 생성합니다.

```solidity theme={null}
function getHash(SpendPermission memory spendPermission) public view returns (bytes32);
```

***

#### `isApproved`

현재 시간이 권한의 유효 기간 안에 있는지와 무관하게, 해당 지출 권한이 승인되었는지 확인합니다.

```solidity theme={null}
function isApproved(SpendPermission memory spendPermission) public view returns (bool);
```

***

#### `isRevoked`

현재 시간이 권한의 유효 기간 안에 있는지와 무관하게, 해당 지출 권한이 철회되었는지 확인합니다.

```solidity theme={null}
function isRevoked(SpendPermission memory spendPermission) public view returns (bool);
```

***

#### `isValid`

현재 시간이 권한의 유효 기간 안에 있는지와 무관하게, 해당 지출 권한이 승인되었고 철회되지 않았는지 확인합니다.

```solidity theme={null}
function isValid(SpendPermission memory spendPermission) public view returns (bool);
```

***

#### `getLastUpdatedPeriod`

지출 권한의 마지막으로 갱신된 기간에 대한 `start`, `end`, 누적 `spend` 값을 조회합니다.

```solidity theme={null}
function getLastUpdatedPeriod(SpendPermission memory spendPermission) public view returns (PeriodSpend memory);
```

***

#### `getCurrentPeriod`

현재 기간에 대한 `start`, `end`, 누적 `spend` 값을 조회합니다. 현재 시간이 권한의 유효 기간 밖이면 revert되지만, 지출 권한이 승인되었는지 또는 철회되었는지는 검사하지 않습니다.

```solidity theme={null}
function getCurrentPeriod(SpendPermission memory spendPermission) public view returns (PeriodSpend memory);
```
