# ChainlinkClientUtils

\_Chainlink client refactored into library and all unused functions removed Uses price aggregator facet of multi collat diamond for storage.

Copy of <https://github.com/smartcontractkit/chainlink/blob/contracts-v0.5.1/contracts/src/v0.8/ChainlinkClient.sol> with only `requestCount` changed to unset so as to be inherited by a proxy implementation.\_

## ChainlinkRequested

```solidity
event ChainlinkRequested(bytes32 id)
```

## ChainlinkFulfilled

```solidity
event ChainlinkFulfilled(bytes32 id)
```

## \_getSlot

```solidity
function _getSlot() internal pure returns (uint256)
```

*Returns storage slot to use when fetching storage relevant to library*

## \_getStorage

```solidity
function _getStorage() internal pure returns (struct IPriceAggregator.PriceAggregatorStorage s)
```

*Returns storage pointer for storage struct in diamond contract, at defined slot*

## buildChainlinkRequest

```solidity
function buildChainlinkRequest(bytes32 specId, address callbackAddr, bytes4 callbackFunctionSignature) internal pure returns (struct Chainlink.Request)
```

Creates a request that can hold additional parameters

### Parameters

| Name                      | Type    | Description                                                   |
| ------------------------- | ------- | ------------------------------------------------------------- |
| specId                    | bytes32 | The Job Specification ID that the request will be created for |
| callbackAddr              | address | address to operate the callback on                            |
| callbackFunctionSignature | bytes4  | function signature to use for the callback                    |

### Return Values

| Name | Type                     | Description                          |
| ---- | ------------------------ | ------------------------------------ |
| \[0] | struct Chainlink.Request | A Chainlink Request struct in memory |

## sendChainlinkRequestTo

```solidity
function sendChainlinkRequestTo(address oracleAddress, struct Chainlink.Request req, uint256 payment) internal returns (bytes32 requestId)
```

Creates a Chainlink request to the specified oracle address

*Generates and stores a request ID, increments the local nonce, and uses `transferAndCall` to send LINK which creates a request on the target oracle contract. Emits ChainlinkRequested event.*

### Parameters

| Name          | Type                     | Description                                |
| ------------- | ------------------------ | ------------------------------------------ |
| oracleAddress | address                  | The address of the oracle for the request  |
| req           | struct Chainlink.Request | The initialized Chainlink Request          |
| payment       | uint256                  | The amount of LINK to send for the request |

### Return Values

| Name      | Type    | Description    |
| --------- | ------- | -------------- |
| requestId | bytes32 | The request ID |

## setChainlinkToken

```solidity
function setChainlinkToken(address _linkErc677) internal
```

Sets the LINK token address

### Parameters

| Name         | Type    | Description                            |
| ------------ | ------- | -------------------------------------- |
| \_linkErc677 | address | The address of the LINK token contract |

## validateChainlinkCallback

```solidity
function validateChainlinkCallback(bytes32 requestId) internal
```

Ensures that the fulfillment is valid for this contract

*Use if the contract developer prefers methods instead of modifiers for validation*

### Parameters

| Name      | Type    | Description                    |
| --------- | ------- | ------------------------------ |
| requestId | bytes32 | The request ID for fulfillment |

## recordChainlinkFulfillment

```solidity
modifier recordChainlinkFulfillment(bytes32 requestId)
```

*Reverts if the sender is not the oracle of the request. Emits ChainlinkFulfilled event.*

### Parameters

| Name      | Type    | Description                    |
| --------- | ------- | ------------------------------ |
| requestId | bytes32 | The request ID for fulfillment |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gains.trade/developer/technical-reference/contracts/libraries/chainlinkclientutils.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
