Skip to content

Commit

Permalink
add dune queries and update tenderly action flow
Browse files Browse the repository at this point in the history
  • Loading branch information
nour-karoui committed Oct 23, 2024
1 parent 20c5824 commit 0c2cb5d
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 43 deletions.
31 changes: 31 additions & 0 deletions periphery/dune/plain_crowdsale_bids.sql
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}}.CrowdSale_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}}.CrowdSale_evt_Bid
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
16 changes: 16 additions & 0 deletions periphery/dune/plain_crowdsale_cumulative_bids.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SELECT
bids.evt_block_time,
SUM(previous_bids.amount) / 1e18 AS cumulative_growth
FROM
ipnft_{{chain}}.Crowdsale_evt_Bid as bids
LEFT JOIN ipnft_{{chain}}.CrowdSale_evt_Bid
AS previous_bids
ON previous_bids.evt_block_time <= bids.evt_block_time
AND previous_bids.saleId = cast('{{saleId}}' as uint256)
WHERE
bids.saleId = cast('{{saleId}}' as uint256)
GROUP BY
bids.evt_block_time,
bids.amount
ORDER BY
bids.evt_block_time;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { ActionFn, Context, TransactionEvent, Event } from '@tenderly/actions'
import axios from 'axios'

const triggerDuneQuery = async (context, event) => {
const triggerDuneQuery: ActionFn = async (context: Context, event: Event) => {
const transactionEvent = event as TransactionEvent
// 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)
const placeBidLog = transactionEvent.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]
//[Cumulative Bids, CrowdSale Bids, Plain Crowdsale Cumulative Bids, Plain Crowdsale Bids]
const duneQueryIds = [2709374, 2709364, 4186294, 4186293]

const query_parameters = {
saleId: saleId,
chain: event.network === '5' ? 'goerli' : 'ethereum'
chain: transactionEvent.network === '11155111' ? 'sepolia' : 'ethereum'
}

for (const queryId of duneQueryIds) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions periphery/tenderly-actions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "tenderly-actions",
"scripts": {
"build": "tsc"
},
"devDependencies": {
"typescript": "^4.3.5"
},
"dependencies": {
"@tenderly/actions": "^0.2.57",
"axios": "^1.7.7"
},
"private": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "out",
"rootDir": "",
"sourceMap": true,
"strict": true,
"target": "es2020"
Expand Down
52 changes: 40 additions & 12 deletions periphery/tenderly.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,66 @@
account_id: ''
project_slug: ''
actions:
moleculeprotocol/project:
tech_prod/catalyst:
runtime: v2
sources: tenderly
sources: tenderly-actions
specs:
BidEventGoerli:
description: BidEvent on Goerli StakedLockingCrowdSale contract
bideventmainnet:
description: BidEvent on Mainnet StakedLockingCrowdSale contract
execution_type: ''
function: dune:triggerDuneQuery
trigger:
type: transaction
transaction:
filters:
- eventEmitted:
contract:
address: 0x46c3369dEce07176Ad7164906D3593AA4C126d35
address: 0x35Bce29F52f51f547998717CD598068Afa2B29B7
name: Bid
network: 5
network: 1
status:
- mined
type: transaction
bideventsepolia:
description: BidEvent on Sepolia StakedLockingCrowdSale contract
execution_type: ''
BidEventMainnet:
description: BidEvent on Mainnet StakedLockingCrowdSale contract
function: dune:triggerDuneQuery
trigger:
transaction:
filters:
- eventEmitted:
contract:
address: 0xd1cE2EA7d3b0C9cAB025A4aD762FC00315141ad7
name: Bid
network: 11155111
status:
- mined
type: transaction
plainbideventmainnet:
description: BidEvent on Mainnet PlainCrowdsale contract
execution_type: ''
function: dune:triggerDuneQuery
trigger:
transaction:
filters:
- eventEmitted:
contract:
address: 0x35Bce29F52f51f547998717CD598068Afa2B29B7
address: 0xf0a8d23f38e9cbbe01c4ed37f23bd519b65bc6c2
name: Bid
network: 1
status:
- mined
type: transaction
plainbideventsepolia:
description: BidEvent on Sepolia PlainCrowdsale contract
execution_type: ''

function: dune:triggerDuneQuery
trigger:
transaction:
filters:
- eventEmitted:
contract:
address: 0x8cA737E2cdaE1Ceb332bEf7ba9eA711a3a2f8037
name: Bid
network: 11155111
status:
- mined
type: transaction
9 changes: 0 additions & 9 deletions periphery/tenderly/package.json

This file was deleted.

0 comments on commit 0c2cb5d

Please sign in to comment.