-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactored code to make onchain req
- Loading branch information
Showing
6 changed files
with
172 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"solidity.defaultCompiler": "localNodeModule" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
interface LinkTokenInterface { | ||
function allowance(address owner, address spender) | ||
external | ||
view | ||
returns (uint256 remaining); | ||
|
||
function approve(address spender, uint256 value) | ||
external | ||
returns (bool success); | ||
|
||
function balanceOf(address owner) external view returns (uint256 balance); | ||
|
||
function decimals() external view returns (uint8 decimalPlaces); | ||
|
||
function decreaseApproval(address spender, uint256 addedValue) | ||
external | ||
returns (bool success); | ||
|
||
function increaseApproval(address spender, uint256 subtractedValue) | ||
external; | ||
|
||
function name() external view returns (string memory tokenName); | ||
|
||
function symbol() external view returns (string memory tokenSymbol); | ||
|
||
function totalSupply() external view returns (uint256 totalTokensIssued); | ||
|
||
function transfer(address to, uint256 value) | ||
external | ||
returns (bool success); | ||
|
||
function transferAndCall( | ||
address to, | ||
uint256 value, | ||
bytes calldata data | ||
) external returns (bool success); | ||
|
||
function transferFrom( | ||
address from, | ||
address to, | ||
uint256 value | ||
) external returns (bool success); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol"; | ||
|
||
contract MetaHuddle is ChainlinkClient { | ||
using Chainlink for Chainlink.Request; | ||
|
||
constructor(address _linkToken) { | ||
linkContract = LinkTokenInterface(_linkToken); | ||
setChainlinkToken(_linkToken); | ||
oracle = 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8; | ||
jobId = "d5270d1c311941d0b08bead21fea7747"; | ||
chainlinkFee = 0.1 * 10**18; | ||
} | ||
|
||
modifier onlyOwner() { | ||
require( | ||
msg.sender == address(0x28172273CC1E0395F3473EC6eD062B6fdFb15940) | ||
); | ||
_; | ||
} | ||
|
||
string private endpoint = | ||
"https://metapass-huddle.herokuapp.com/api/getHuddle"; | ||
|
||
// Chainlink Variables | ||
uint256 public volume; | ||
address private oracle; | ||
bytes32 private jobId; | ||
uint256 private chainlinkFee; | ||
LinkTokenInterface public linkContract; | ||
|
||
function getHuddleLink(address child) public returns (bytes32 link) { | ||
Chainlink.Request memory request = buildChainlinkRequest( | ||
jobId, | ||
address(this), | ||
this.fulfill.selector | ||
); | ||
request.add("get", makeString(toAsciiString(child))); | ||
return sendChainlinkRequestTo(oracle, request, chainlinkFee); | ||
} | ||
|
||
function makeString(string memory child) | ||
public | ||
view | ||
returns (string memory) | ||
{ | ||
return string(abi.encodePacked(endpoint, "/", child)); | ||
} | ||
|
||
function fulfill(bytes32 _requestId, uint256 _volume) | ||
public | ||
recordChainlinkFulfillment(_requestId) | ||
{ | ||
volume = _volume; | ||
} | ||
|
||
function withdrawLink() public onlyOwner { | ||
linkContract.transfer( | ||
msg.sender, | ||
linkContract.balanceOf(address(this)) | ||
); | ||
} | ||
|
||
function toAsciiString(address x) public pure returns (string memory) { | ||
bytes memory s = new bytes(40); | ||
for (uint256 i = 0; i < 20; i++) { | ||
bytes1 b = bytes1(uint8(uint256(uint160(x)) / (2**(8 * (19 - i))))); | ||
bytes1 hi = bytes1(uint8(b) / 16); | ||
bytes1 lo = bytes1(uint8(b) - 16 * uint8(hi)); | ||
s[2 * i] = char(hi); | ||
s[2 * i + 1] = char(lo); | ||
} | ||
return string(abi.encodePacked("0x", s)); | ||
} | ||
|
||
function char(bytes1 b) public pure returns (bytes1 c) { | ||
if (uint8(b) < 10) return bytes1(uint8(b) + 0x30); | ||
else return bytes1(uint8(b) + 0x57); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
const hre = require("hardhat"); | ||
|
||
async function main() { | ||
const MetapassFactory = await hre.ethers.getContractFactory( | ||
"MetapassFactory" | ||
); | ||
const factoryContract = await MetapassFactory.deploy( | ||
"0x6a956a4C72203e111BA5B5d396bc0ad286AeBd9e" | ||
); | ||
const MetapassFactory = await hre.ethers.getContractFactory( | ||
"MetapassFactory" | ||
); | ||
const factoryContract = await MetapassFactory.deploy( | ||
"0x3e4f13d936176A1cD21757d2725e66Af6F1c12C5", | ||
"0x9e248FdC510E96556635dbF354605533e005337f" | ||
); | ||
|
||
await factoryContract.deployed(); | ||
await factoryContract.deployed(); | ||
|
||
console.log("Factory contract deployed to:", factoryContract.address); | ||
console.log("Factory contract deployed to:", factoryContract.address); | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const hre = require("hardhat"); | ||
|
||
async function main() { | ||
const MetaHuddle = await hre.ethers.getContractFactory("MetaHuddle"); | ||
const huddleContract = await MetaHuddle.deploy( | ||
"0x326c977e6efc84e512bb9c30f76e30c160ed06fb" | ||
); | ||
|
||
await huddleContract.deployed(); | ||
|
||
console.log("Huddle contract deployed to:", huddleContract.address); | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |