Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions evm/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/generated
8 changes: 3 additions & 5 deletions evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
"postbuild": "yarn generate-typings && yarn tsc && cp -f src/generated/*.d.ts dist/src/generated",
"build:windows": "truffle.cmd build",
"depcheck": "echo 'chainlink' && depcheck --ignore-dirs=build/contracts,v0.5,box || true",
"eslint": "eslint --ext .ts,.js test",
"eslint": "eslint --ext .ts,.js testv2 src",
"solhint": "solhint ./contracts/**/*.sol",
"lint": "yarn solhint && yarn eslint",
"slither": "truffle compile --quiet && slither .",
"pretest": "yarn build",
"test:v1": "tsc && truffle test ./dist/test/*.js",
"test:v2": "jest --testTimeout 20000",
"test": "yarn test:v1 && yarn test:v2",
"format": "prettier --write \"{src,test,testv2}/*/**\"",
"test": "jest --testTimeout 20000",
"format": "prettier --write \"{src,testv2}/*/**\"",
"prepublishOnly": "yarn build && yarn lint && yarn test",
"setup": "ts-node ./scripts/build",
"truffle:migrate:cldev": "truffle migrate --network cldev"
Expand Down
52 changes: 23 additions & 29 deletions evm/src/helpersV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LinkToken } from './generated/LinkToken'
import { makeDebug } from './debug'
import cbor from 'cbor'
import { EmptyOracle } from './generated/EmptyOracle'
import { OracleFactory } from './generated/OracleFactory'

const debug = makeDebug('helpers')

Expand Down Expand Up @@ -297,11 +298,13 @@ export function keccak(
return utils.keccak256(...args)
}

type TxOptions = Omit<ethers.providers.TransactionRequest, 'to' | 'from'>

export async function fulfillOracleRequest(
oracleContract: Oracle | EmptyOracle,
runRequest: RunRequest,
response: string,
options: Omit<ethers.providers.TransactionRequest, 'to' | 'from'> = {
options: TxOptions = {
gasLimit: 1000000, // FIXME: incorrect gas estimation
},
): ReturnType<typeof oracleContract.fulfillOracleRequest> {
Expand All @@ -326,55 +329,46 @@ export async function fulfillOracleRequest(
)
}

/**
* The solidity function selector for the given signature
*/
export function functionSelector(signature: string): string {
const fullHash = ethers.utils.id(signature)
assert(fullHash.startsWith('0x'))
return fullHash.slice(0, 2 + 4 * 2) // '0x' + initial 4 bytes, in hex
export async function cancelOracleRequest(
oracleContract: Oracle | EmptyOracle,
request: RunRequest,
options: TxOptions = {},
): ReturnType<typeof oracleContract.cancelOracleRequest> {
return oracleContract.cancelOracleRequest(
request.id,
request.payment,
request.callbackFunc,
request.expiration,
options,
)
}

export function requestDataBytes(
specId: string,
to: string,
fHash: string,
nonce: number,
data: string,
): any {
const types = [
'address',
'uint256',
'bytes32',
'address',
'bytes4',
'uint256',
'uint256',
'bytes',
]
dataBytes: string,
): string {
const ocFactory = new OracleFactory()

const values = [
return ocFactory.interface.functions.oracleRequest.encode([
ethers.constants.AddressZero,
0,
specId,
to,
fHash,
nonce,
1,
data,
]
const encoded = ethers.utils.defaultAbiCoder.encode(types, values)
const funcSelector = functionSelector(
'oracleRequest(address,uint256,bytes32,address,bytes4,uint256,uint256,bytes)',
)
return `${funcSelector}${stripHexPrefix(encoded)}`
dataBytes,
])
}

// link param must be from linkContract(), if amount is a BN
export function requestDataFrom(
oc: Oracle,
link: LinkToken,
amount: number,
amount: ethers.utils.BigNumberish,
args: string,
options: Omit<ethers.providers.TransactionRequest, 'to' | 'from'> = {},
): ReturnType<typeof link.transferAndCall> {
Expand Down
Loading