-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Web3 Action to trigger Dune Queries (#139)
* adds tenderly web3 action to trigger dune queries after Bid event in StakedLockedCrowdSale * - moved constants to storage context - merged dependencies into package.json of repo * - commits hash of Bid event signature to source and adds comment * - update README * Dune Query Updates (#140) * reorders tenderly files versions dune sql queries Signed-off-by: Stefan Adolf <[email protected]> * drops ipnft prefix updates cumulative bids query Signed-off-by: Stefan Adolf <[email protected]> * uses generic prices table to fetch decimals reduces crowdsale bids query Signed-off-by: Stefan Adolf <[email protected]> * falls back to generic tokens.erc20 spell Signed-off-by: stadolf <[email protected]> --------- Signed-off-by: Stefan Adolf <[email protected]> Signed-off-by: stadolf <[email protected]> --------- Signed-off-by: Stefan Adolf <[email protected]> Signed-off-by: stadolf <[email protected]> Co-authored-by: Stefan Adolf <[email protected]>
- Loading branch information
1 parent
40d8f9a
commit c4edb42
Showing
10 changed files
with
283 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
with bids as ( | ||
SELECT | ||
Bidder as bidder, | ||
sum(amount) as bid_size | ||
FROM | ||
ipnft_{{chain}}.StakedLockingCrowdSale_evt_Bid | ||
WHERE | ||
saleId = cast('{{saleId}}' as uint256) | ||
GROUP BY | ||
Bidder, | ||
amount | ||
ORDER BY | ||
bid_size DESC | ||
), | ||
decimals as ( | ||
SELECT erc20.decimals | ||
FROM | ||
(SELECT from_hex(json_extract_scalar(sale, '$.biddingToken')) as biddingTokenContract | ||
FROM | ||
ipnft_{{chain}}.StakedLockingCrowdSale_evt_Started | ||
WHERE | ||
saleId = cast('{{saleId}}' as uint256) | ||
) as sale | ||
LEFT JOIN tokens.erc20 as erc20 | ||
ON erc20.blockchain = '{{chain}}' | ||
AND erc20.contract_address = sale.biddingTokenContract | ||
) | ||
select | ||
Bidder, | ||
bid_size / pow(10, COALESCE(decimals,18)) as bid_amount | ||
FROM bids, decimals |
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,15 @@ | ||
SELECT | ||
bids.evt_block_time, | ||
SUM(previous_bids.amount) / 1e18 AS cumulative_growth | ||
FROM | ||
ipnft_{{chain}}.StakedLockingCrowdSale_evt_Bid as bids | ||
LEFT JOIN ipnft_{{chain}}.StakedLockingCrowdSale_evt_Bid | ||
AS previous_bids | ||
ON previous_bids.evt_block_time <= bids.evt_block_time | ||
WHERE | ||
bids.saleId = cast('{{saleId}}' as uint256) | ||
GROUP BY | ||
bids.evt_block_time, | ||
bids.amount | ||
ORDER BY | ||
bids.evt_block_time; |
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,38 @@ | ||
account_id: '' | ||
project_slug: '' | ||
actions: | ||
moleculeprotocol/project: | ||
runtime: v2 | ||
sources: tenderly | ||
specs: | ||
BidEventGoerli: | ||
description: BidEvent on Goerli StakedLockingCrowdSale contract | ||
function: dune:triggerDuneQuery | ||
trigger: | ||
type: transaction | ||
transaction: | ||
filters: | ||
- eventEmitted: | ||
contract: | ||
address: 0x46c3369dEce07176Ad7164906D3593AA4C126d35 | ||
name: Bid | ||
network: 5 | ||
status: | ||
- mined | ||
execution_type: '' | ||
BidEventMainnet: | ||
description: BidEvent on Mainnet StakedLockingCrowdSale contract | ||
function: dune:triggerDuneQuery | ||
trigger: | ||
type: transaction | ||
transaction: | ||
filters: | ||
- eventEmitted: | ||
contract: | ||
address: 0x35Bce29F52f51f547998717CD598068Afa2B29B7 | ||
name: Bid | ||
network: 1 | ||
status: | ||
- mined | ||
execution_type: '' | ||
|
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,5 @@ | ||
# Dependency directories | ||
node_modules/ | ||
|
||
# Ignore tsc output | ||
out/**/* |
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,43 @@ | ||
import axios from 'axios' | ||
|
||
const triggerDuneQuery = async (context, event) => { | ||
// keccak256(Bid(uint256 saleId,address bidder,uint256 amount)); | ||
const BID_EVENT_SIG = | ||
'0xdcd726e11f8b5e160f00290f0fe3a1abb547474e53a8e7a8f49a85e7b1ca3199' | ||
|
||
const placeBidLog = event.logs.find((log) => log.topics[0] === BID_EVENT_SIG) | ||
if (!placeBidLog) return | ||
|
||
const saleId = BigInt(placeBidLog.topics[1]).toString() | ||
const DUNE_API_KEY = await context.secrets.get('DUNE_API_KEY') | ||
|
||
//[Cumulative Bids, CrowdSale Bids] | ||
const duneQueryIds = [2709374, 2709364] | ||
|
||
const query_parameters = { | ||
saleId: saleId, | ||
chain: event.network === '5' ? 'goerli' : 'ethereum' | ||
} | ||
|
||
for (const queryId of duneQueryIds) { | ||
try { | ||
const res = await axios.post( | ||
`https://api.dune.com/api/v1/query/${queryId}/execute`, | ||
{ | ||
query_parameters | ||
}, | ||
{ | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-Dune-API-Key': DUNE_API_KEY | ||
} | ||
} | ||
) | ||
console.log('response >> ', res.data) | ||
} catch (e) { | ||
console.log('error >> ', e) | ||
} | ||
} | ||
} | ||
|
||
module.exports = { triggerDuneQuery } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,9 @@ | ||
{ | ||
"name": "@moleculeprotocol/web3-actions", | ||
"private": true, | ||
"scripts": {}, | ||
"dependencies": { | ||
"@tenderly/actions": "^0.2.0", | ||
"axios": "^1.4.0" | ||
} | ||
} |
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,18 @@ | ||
{ | ||
"compileOnSave": true, | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"noImplicitReturns": true, | ||
"noUnusedLocals": true, | ||
"outDir": "out", | ||
"sourceMap": true, | ||
"strict": true, | ||
"target": "es2020" | ||
}, | ||
"exclude": [ | ||
"**/*.spec.ts" | ||
], | ||
"include": [ | ||
"**/*" | ||
] | ||
} |