Skip to content

Commit

Permalink
add Transak validation
Browse files Browse the repository at this point in the history
  • Loading branch information
UyenNhi committed Jun 6, 2023
1 parent 8710cc6 commit ec31386
Show file tree
Hide file tree
Showing 236 changed files with 11,135 additions and 2,097 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/1dd7084feacead7ea9808bb89c4ee94a.json"
}
10 changes: 10 additions & 0 deletions artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "Strings",
"sourceName": "@openzeppelin/contracts/utils/Strings.sol",
"abi": [],
"bytecode": "0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220554120e6795de1095fd54992294a43b7bbd9d054b9da4b5204aea17e03b6254e64736f6c63430008110033",
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220554120e6795de1095fd54992294a43b7bbd9d054b9da4b5204aea17e03b6254e64736f6c63430008110033",
"linkReferences": {},
"deployedLinkReferences": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../build-info/1dd7084feacead7ea9808bb89c4ee94a.json"
}
10 changes: 10 additions & 0 deletions artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "Math",
"sourceName": "@openzeppelin/contracts/utils/math/Math.sol",
"abi": [],
"bytecode": "0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220feec7b17524d34f3c20d4922777dea9e0c157695b6e02a8bd0951b2ebf853fa864736f6c63430008110033",
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220feec7b17524d34f3c20d4922777dea9e0c157695b6e02a8bd0951b2ebf853fa864736f6c63430008110033",
"linkReferences": {},
"deployedLinkReferences": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../build-info/d951a07aa61d2207e90859c4cbb7e474.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "SafeMath",
"sourceName": "@openzeppelin/contracts/utils/math/SafeMath.sol",
"abi": [],
"bytecode": "0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212208e77a4680532ae9e9e61e1cd4ff6be2a8d9dddec98c69552d2944258cddde66d64736f6c63430008110033",
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212208e77a4680532ae9e9e61e1cd4ff6be2a8d9dddec98c69552d2944258cddde66d64736f6c63430008110033",
"linkReferences": {},
"deployedLinkReferences": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../../../build-info/1dd7084feacead7ea9808bb89c4ee94a.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "SignedMath",
"sourceName": "@openzeppelin/contracts/utils/math/SignedMath.sol",
"abi": [],
"bytecode": "0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220c5d6c734e147510a4cba68515ad7f9014cd66d2f51dc998c071d660dc98eca8564736f6c63430008110033",
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220c5d6c734e147510a4cba68515ad7f9014cd66d2f51dc998c071d660dc98eca8564736f6c63430008110033",
"linkReferences": {},
"deployedLinkReferences": {}
}
1 change: 1 addition & 0 deletions artifacts/build-info/1dd7084feacead7ea9808bb89c4ee94a.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions artifacts/build-info/d951a07aa61d2207e90859c4cbb7e474.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions artifacts/build-info/f2eb4e173b43c52d2ccd8f62dc3118c6.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion artifacts/build-info/ffff62e34f1018458229b74fccd2a227.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/ffff62e34f1018458229b74fccd2a227.json"
"buildInfo": "../../build-info/f2eb4e173b43c52d2ccd8f62dc3118c6.json"
}
112 changes: 110 additions & 2 deletions artifacts/contracts/AdmodConsumer.sol/AdmodConsumer.json

Large diffs are not rendered by default.

151 changes: 148 additions & 3 deletions cache/solidity-files-cache.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"_format": "hh-sol-cache-2",
"files": {
"/home/hayden/chainlink_hackathon/chainlink_hkt/contracts/AdmodConsumer.sol": {
"lastModificationDate": 1685877333506,
"contentHash": "3adead03205e8b2671c79d94b7f4902d",
"lastModificationDate": 1686070365414,
"contentHash": "b88e582c91ad7c22f7962b1f2a413774",
"sourceName": "contracts/AdmodConsumer.sol",
"solcConfig": {
"version": "0.8.17",
Expand All @@ -30,7 +30,9 @@
},
"imports": [
"@chainlink/contracts/src/v0.8/ChainlinkClient.sol",
"@chainlink/contracts/src/v0.8/ConfirmedOwner.sol"
"@chainlink/contracts/src/v0.8/ConfirmedOwner.sol",
"@openzeppelin/contracts/utils/math/SafeMath.sol",
"@openzeppelin/contracts/utils/Strings.sol"
],
"versionPragmas": [
"0.8.17"
Expand Down Expand Up @@ -548,6 +550,149 @@
"artifacts": [
"OwnableInterface"
]
},
"/home/hayden/chainlink_hackathon/chainlink_hkt/node_modules/@openzeppelin/contracts/utils/math/SafeMath.sol": {
"lastModificationDate": 1686061704515,
"contentHash": "f6f4fda16c536e57069af40a245c985e",
"sourceName": "@openzeppelin/contracts/utils/math/SafeMath.sol",
"solcConfig": {
"version": "0.8.17",
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [],
"versionPragmas": [
"^0.8.0"
],
"artifacts": [
"SafeMath"
]
},
"/home/hayden/chainlink_hackathon/chainlink_hkt/node_modules/@openzeppelin/contracts/utils/Strings.sol": {
"lastModificationDate": 1686061704519,
"contentHash": "48686fc32a22a3754b8e63321857dd2a",
"sourceName": "@openzeppelin/contracts/utils/Strings.sol",
"solcConfig": {
"version": "0.8.17",
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [
"./math/Math.sol",
"./math/SignedMath.sol"
],
"versionPragmas": [
"^0.8.0"
],
"artifacts": [
"Strings"
]
},
"/home/hayden/chainlink_hackathon/chainlink_hkt/node_modules/@openzeppelin/contracts/utils/math/SignedMath.sol": {
"lastModificationDate": 1686061704515,
"contentHash": "9488ebd4daacfee8ad04811600d7d061",
"sourceName": "@openzeppelin/contracts/utils/math/SignedMath.sol",
"solcConfig": {
"version": "0.8.17",
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [],
"versionPragmas": [
"^0.8.0"
],
"artifacts": [
"SignedMath"
]
},
"/home/hayden/chainlink_hackathon/chainlink_hkt/node_modules/@openzeppelin/contracts/utils/math/Math.sol": {
"lastModificationDate": 1686061704483,
"contentHash": "fe63409d8a06818b926cf89e0ea88b1b",
"sourceName": "@openzeppelin/contracts/utils/math/Math.sol",
"solcConfig": {
"version": "0.8.17",
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [],
"versionPragmas": [
"^0.8.0"
],
"artifacts": [
"Math"
]
}
}
}
77 changes: 72 additions & 5 deletions contracts/AdmodConsumer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,28 @@ pragma solidity 0.8.17;

import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";
import "@chainlink/contracts/src/v0.8/ConfirmedOwner.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

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

using SafeMath for uint;


// the earning amount of this week
uint256 public earning;

bytes32 private jobId;
// the amount of LINK bought from Transak with $earning amount
uint256 public linkAmount;

// 2 separate jobId for google AdmodAPI and TransakAPI
bytes32 public ggJobId;
bytes32 public transakJobId;

uint256 private fee;
mapping(uint256 => uint256) public earningReports;
bool public isEligible;

/**
* @notice
Expand All @@ -21,22 +34,26 @@ contract AdmodConsumer is ChainlinkClient, ConfirmedOwner {
address public beneficiary;

event RequestEarning(bytes32 indexed requestId, uint256 earning);
event RequestBoughtAmount(bytes32 indexed requestId, uint256 linkAmount);


/**
* @notice Initialize the link token and target oracle
*
* Mumbai Testnet details:
* Link Token: 0x326C977E6efc84E512bB9C30f76E30c160eD06FB
* Oracle: 0xaA37473c8d78F0f1C86c9d8aEE53E8B896bCB4D5
* jobId: b1d42cd54a3a4200b1f725a68e488888
*
* ggJobId: b1d42cd54a3a4200b1f725a68e488888
* transakJobId: b1d42cd54a3a4200b1f725a68e488999
*/
constructor(address _owner, address _beneficiary) ConfirmedOwner(_owner) {
setChainlinkToken(0x326C977E6efc84E512bB9C30f76E30c160eD06FB);
setChainlinkOracle(0xaA37473c8d78F0f1C86c9d8aEE53E8B896bCB4D5);
jobId = "b1d42cd54a3a4200b1f725a68e488888";
ggJobId = "b1d42cd54a3a4200b1f725a68e488888";
transakJobId = "b1d42cd54a3a4200b1f725a68e488999";
fee = (1 * LINK_DIVISIBILITY) / 10; // 0,1 * 10**18 (Varies by network and job)
beneficiary = _beneficiary;
isEligible = false;
}

/**
Expand All @@ -45,7 +62,7 @@ contract AdmodConsumer is ChainlinkClient, ConfirmedOwner {
*/
function requestWeekEarning() public returns (bytes32 requestId) {
Chainlink.Request memory req = buildChainlinkRequest(
jobId,
ggJobId,
address(this),
this.fulfill.selector
);
Expand Down Expand Up @@ -74,6 +91,45 @@ contract AdmodConsumer is ChainlinkClient, ConfirmedOwner {
@notice earning will be a total of earning this week subtract for Transak transaction fee
*/
earning = _earning;
_requestTransakValidation();
}

function _requestTransakValidation() private returns (bytes32 requestId) {
Chainlink.Request memory req = buildChainlinkRequest(
transakJobId,
address(this),
this.fulfillTransakPrice.selector
);

uint256 headEarning = SafeMath.div(earning,1000000);
uint256 tailEarning = SafeMath.mod(earning,1000000);

string memory apiUrl = string(abi.encodePacked("https://api-stg.transak.com/api/v2/currencies/price?partnerApiKey=062525f0-856b-4302-9d48-8b690bb5e634&fiatCurrency=USD&cryptoCurrency=ETH&isBuyOrSell=BUY&network=ethereum&paymentMethod=credit_debit_card&fiatAmount=",
Strings.toString(headEarning),".",Strings.toString(tailEarning)));

// Set the URL to perform the GET request on
req.add(
"get",
apiUrl
);

req.add("path", "response,cryptoAmount");
req.addUint("times", LINK_DIVISIBILITY);

// Sends the request
return sendChainlinkRequest(req, fee);
}

function fulfillTransakPrice(
bytes32 _requestId,
uint256 _linkAmount
) public recordChainlinkFulfillment(_requestId) {
emit RequestBoughtAmount(_requestId, _linkAmount);
/**
@notice earning will be a total of earning this week subtract for Transak transaction fee
*/
linkAmount = _linkAmount;
_checkEligibleEarning();
}

/** @notice
Expand All @@ -88,4 +144,15 @@ contract AdmodConsumer is ChainlinkClient, ConfirmedOwner {
"Unable to transfer"
);
}

function _checkEligibleEarning() private {
LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
if (link.balanceOf(beneficiary) == linkAmount)
{
earningReports[block.number] = earning;
isEligible = true;
}
else isEligible = false;
}

}
Loading

0 comments on commit ec31386

Please sign in to comment.