Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ijonas committed May 20, 2022
1 parent cdc4021 commit 8bb51e4
Show file tree
Hide file tree
Showing 15 changed files with 610 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 translucent-link
Copyright (c) 2022 Translucent

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# chainlink-node-jobs

Contains jobspecs, example client contracts and supporting documentation for all our public Chainlink jobs.

## Jobs
We currently make available the following public jobs:

* Get > Uint256 - retrieve uint256, e.g. fetch the current ETH price.
* Get > Uint256, Uint256 - retrieve two uint256, e.g. fetch the high and low price of the day
* Get > Uint256[] - retrieve a list of uint256, e.g. fetch a series of prices
* Get > Bytes - retrieve a variable length string

## Networks
Our public jobs are currently available on the following networks:

* Ethernet Rinkeby
* Ethernet Kovan
* Polygon Mumbai
* Polygon Mainnet
45 changes: 45 additions & 0 deletions polygon-mumbai/Get > Bytes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Get > Bytes

This job retrieves a variable-length string from an internet-facing JSON API.

## Contract Address & JobID

Contract: [0x1314E350Fc5a3896E2d66C43A83D9391E914a004](https://mumbai.polygonscan.com/address/0x1314E350Fc5a3896E2d66C43A83D9391E914a004)

JobID: 490d815cbbb74a0db1d17e7aae3deb84

## Parameters

The job requires the following parameters to be specified:

* `get` - internet-facing URL from where the bytes/string is retrieved
* `path` - comma-separated JSON path used to extract the integer value

## Price

0.05 LINK

## Example

If you set the following parameters

* get : https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD
* path : RAW,ETH,USD,IMAGEURL

Note: use commas not dots for JSON paths.

You will receive a JSON response that may look like this:

{
"RAW": {
"ETH": {
"USD": {
"IMAGEURL": "/media/37746238/eth.png"
}
}
}
}

The job populated with the example parameters above would return with: `/media/37746238/eth.png`

See [example.sol](example.sol) for an example client contract.
74 changes: 74 additions & 0 deletions polygon-mumbai/Get > Bytes/example.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";

/**
* @notice DO NOT USE THIS CODE IN PRODUCTION. This is an example contract.
*/
contract GenericLargeResponse is ChainlinkClient {
using Chainlink for Chainlink.Request;

// variable bytes returned in a single oracle response
bytes public data;
string public stringData;
uint256 private constant ORACLE_PAYMENT =
((1 * LINK_DIVISIBILITY) / 100) * 5; // 0.05LINK

string constant jobId = "490d815cbbb74a0db1d17e7aae3deb84"; // MUMBAI

/**
* @notice Initialize the link token and target oracle
* @dev The oracle address must be an Operator contract for multiword response
*/
constructor() {
// MUMBAI
setChainlinkToken(0x326C977E6efc84E512bB9C30f76E30c160eD06FB);
setChainlinkOracle(0x1314E350Fc5a3896E2d66C43A83D9391E914a004);
}

/**
* @notice Request variable bytes from the oracle
*/
function requestBytes(string memory _url, string memory _path) public {
Chainlink.Request memory req = buildChainlinkRequest(
stringToBytes32(jobId),
address(this),
this.fulfillBytes.selector
);
req.add("get", _url);
req.add("path", _path);
sendOperatorRequest(req, ORACLE_PAYMENT);
}

event RequestFulfilled(bytes32 indexed requestId, bytes indexed data);

/**
* @notice Fulfillment function for variable bytes
* @dev This is called by the oracle. recordChainlinkFulfillment must be used.
*/
function fulfillBytes(bytes32 requestId, bytes memory bytesData)
public
recordChainlinkFulfillment(requestId)
{
emit RequestFulfilled(requestId, bytesData);
data = bytesData;
stringData = string(data);
}

function stringToBytes32(string memory source)
private
pure
returns (bytes32 result)
{
bytes memory tempEmptyStringTest = bytes(source);
if (tempEmptyStringTest.length == 0) {
return 0x0;
}

assembly {
// solhint-disable-line no-inline-assembly
result := mload(add(source, 32))
}
}
}
30 changes: 30 additions & 0 deletions polygon-mumbai/Get > Bytes/jobspec.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
type = "directrequest"
schemaVersion = 1
name = "Get > Bytes"
externalJobID = "490d815c-bbb7-4a0d-b1d1-7e7aae3deb84"
maxTaskDuration = "0s"
contractAddress = "0x1314E350Fc5a3896E2d66C43A83D9391E914a004"
minIncomingConfirmations = 0
minContractPaymentLinkJuels = 50000000000000000
observationSource = """
decode_log [type="ethabidecodelog"
abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)"
data="$(jobRun.logData)"
topics="$(jobRun.logTopics)"]
decode_cbor [type="cborparse" data="$(decode_log.data)"]
fetch [type="http" method=GET url="$(decode_cbor.get)"]
parse [type="jsonparse" path="$(decode_cbor.path)" data="$(fetch)"]
encode_large [type="ethabiencode"
abi="(bytes32 requestId, bytes _data)"
data="{\\"requestId\\": $(decode_log.requestId), \\"_data\\": $(parse)}"
]
encode_tx [type="ethabiencode"
abi="fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes calldata data)"
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_large)}"
]
submit_tx [type="ethtx" to="0x1314E350Fc5a3896E2d66C43A83D9391E914a004" data="$(encode_tx)"]
decode_log -> decode_cbor -> fetch -> parse -> encode_large -> encode_tx -> submit_tx
"""
52 changes: 52 additions & 0 deletions polygon-mumbai/Get > Uint256,Uint256/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Get > Uint256,Uint256

This job retrieves two `uint256` integers from a internet-facing JSON API.

## Contract Address & JobID

Contract: [0x1314E350Fc5a3896E2d66C43A83D9391E914a004](https://mumbai.polygonscan.com/address/0x1314E350Fc5a3896E2d66C43A83D9391E914a004)

JobID: 437d298d210c4fff935dcedb97ea8011

## Parameters

The job requires the following parameters to be specified:

* `get` - internet-facing URL from where the integer is retrieved
* `path1` - comma-separated JSON path used to extract the first integer value
* `path2` - comma-separated JSON path used to extract the second integer value
* `multiply` - factor using to deal with precision and rounding errors

Note: use commas not dots for JSON paths.

## Price

0.05 LINK

## Example

If you set the following parameters

* get : https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD
* path1 : RAW,ETH,USD,HIGHDAY
* path2 : RAW,ETH,USD,LOWDAY
* price : 100

Note: use commas not dots for JSON paths.

You will receive a JSON response that may look like this:

{
"RAW": {
"ETH": {
"USD": {
"HIGHDAY": 2061.81,
"LOWDAY": 2000.51
}
}
}
}

The job populated with the example parameters above would return with: `206181` & `200051`

See [example.sol](example.sol) for an example client contract.
72 changes: 72 additions & 0 deletions polygon-mumbai/Get > Uint256,Uint256/example.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";
import "@chainlink/contracts/src/v0.8/ConfirmedOwner.sol";

contract MultiVariableRequest is ChainlinkClient, ConfirmedOwner {
using Chainlink for Chainlink.Request;

uint256 private constant ORACLE_PAYMENT =
((1 * LINK_DIVISIBILITY) / 100) * 5;
uint256 public val1;
uint256 public val2;

string constant jobId = "437d298d210c4fff935dcedb97ea8011";

constructor() ConfirmedOwner(msg.sender) {
// MUMBAI
setChainlinkToken(0x326C977E6efc84E512bB9C30f76E30c160eD06FB);
setChainlinkOracle(0x1314E350Fc5a3896E2d66C43A83D9391E914a004);
}

function requestValues(
string memory _url,
string memory _path1,
string memory _path2,
int256 _multiply
) public onlyOwner {
Chainlink.Request memory req = buildChainlinkRequest(
stringToBytes32(jobId),
address(this),
this.fulfillValues.selector
);
req.add("get", _url);
req.add("path1", _path1);
req.add("path2", _path2);
req.addInt("multiply", _multiply);
sendOperatorRequest(req, ORACLE_PAYMENT);
}

event RequestFulfilledValues(
bytes32 requestId,
uint256 indexed val1,
uint256 indexed val2
);

function fulfillValues(
bytes32 requestId,
uint256 _val1,
uint256 _val2
) public recordChainlinkFulfillment(requestId) {
emit RequestFulfilledValues(requestId, _val1, _val2);
val1 = _val1;
val2 = _val2;
}

function stringToBytes32(string memory source)
private
pure
returns (bytes32 result)
{
bytes memory tempEmptyStringTest = bytes(source);
if (tempEmptyStringTest.length == 0) {
return 0x0;
}

assembly {
// solhint-disable-line no-inline-assembly
result := mload(add(source, 32))
}
}
}
29 changes: 29 additions & 0 deletions polygon-mumbai/Get > Uint256,Uint256/jobspec.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
type = "directrequest"
schemaVersion = 1
name = "Get > Uint256,Uint256 0.05LINK"
maxTaskDuration = "0s"
externalJobID = "437d298d-210c-4fff-935d-cedb97ea8011"
contractAddress = "0x1314E350Fc5a3896E2d66C43A83D9391E914a004"
minIncomingConfirmations = 0
minContractPaymentLinkJuels = 50000000000000000
observationSource = """
decode_log [type="ethabidecodelog"
abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)"
data="$(jobRun.logData)"
topics="$(jobRun.logTopics)"]
decode_cbor [type="cborparse" data="$(decode_log.data)"]
fetch [type="http" method=GET url="$(decode_cbor.get)"]
parseVal1 [type="jsonparse" path="$(decode_cbor.path1)" data="$(fetch)"]
parseVal2 [type="jsonparse" path="$(decode_cbor.path2)" data="$(fetch)"]
multiplyVal1 [type="multiply" input="$(parseVal1)" times="$(decode_cbor.multiply)"]
multiplyVal2 [type="multiply" input="$(parseVal2)" times="$(decode_cbor.multiply)"]
encode_data [type="ethabiencode" abi="(bytes32 requestId, uint256 val1, uint256 val2)" data="{ \\"requestId\\": $(decode_log.requestId), \\"val1\\": $(multiplyVal1), \\"val2\\": $(multiplyVal2)}"]
encode_tx [type="ethabiencode"
abi="fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes calldata data)"
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}"
]
submit_tx [type="ethtx" to="0x1314E350Fc5a3896E2d66C43A83D9391E914a004" data="$(encode_tx)"]
decode_log -> decode_cbor -> fetch -> parseVal1 -> multiplyVal1 -> parseVal2 -> multiplyVal2 -> encode_data -> encode_tx -> submit_tx
"""
49 changes: 49 additions & 0 deletions polygon-mumbai/Get > Uint256/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Get > Uint256

This job retrieves a `uint256` integer from a internet-facing JSON API.

## Contract Address & JobID

Contract: [0x1314E350Fc5a3896E2d66C43A83D9391E914a004](https://mumbai.polygonscan.com/address/0x1314E350Fc5a3896E2d66C43A83D9391E914a004)

JobID: 9ee6d657668a4ccfaaab03b73c703fc6

## Parameters

The job requires the following parameters to be specified:

* `get` - internet-facing URL from where the integer is retrieved
* `path` - comma-separated JSON path used to extract the integer value
* `multiply` - factor using to deal with precision and rounding errors

Note: use commas not dots for JSON paths.

## Price

0.05 LINK

## Example

If you set the following parameters

* get : https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD
* path : RAW,ETH,USD,PRICE
* price : 100

Note: use commas not dots for JSON paths.

You will receive a JSON response that may look like this:

{
"RAW": {
"ETH": {
"USD": {
"PRICE": 2045.32
}
}
}
}

The job populated with the example parameters above would return with: `204532`

See [example.sol](example.sol) for an example client contract.
Loading

0 comments on commit 8bb51e4

Please sign in to comment.