From 0c2cb5d83c46d462219917292e43b2f272ef0f45 Mon Sep 17 00:00:00 2001 From: nour-karoui Date: Wed, 23 Oct 2024 14:32:51 +0200 Subject: [PATCH] add dune queries and update tenderly action flow --- periphery/dune/plain_crowdsale_bids.sql | 31 +++++++++++ .../dune/plain_crowdsale_cumulative_bids.sql | 16 ++++++ .../{tenderly => tenderly-actions}/.gitignore | 0 .../dune.js => tenderly-actions/dune.ts} | 14 +++-- .../package-lock.json | 50 ++++++++++++------ periphery/tenderly-actions/package.json | 14 +++++ .../tsconfig.json | 1 + periphery/tenderly.yaml | 52 ++++++++++++++----- periphery/tenderly/package.json | 9 ---- 9 files changed, 144 insertions(+), 43 deletions(-) create mode 100644 periphery/dune/plain_crowdsale_bids.sql create mode 100644 periphery/dune/plain_crowdsale_cumulative_bids.sql rename periphery/{tenderly => tenderly-actions}/.gitignore (100%) rename periphery/{tenderly/dune.js => tenderly-actions/dune.ts} (62%) rename periphery/{tenderly => tenderly-actions}/package-lock.json (68%) create mode 100755 periphery/tenderly-actions/package.json rename periphery/{tenderly => tenderly-actions}/tsconfig.json (93%) delete mode 100755 periphery/tenderly/package.json diff --git a/periphery/dune/plain_crowdsale_bids.sql b/periphery/dune/plain_crowdsale_bids.sql new file mode 100644 index 00000000..67e8e7dd --- /dev/null +++ b/periphery/dune/plain_crowdsale_bids.sql @@ -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 \ No newline at end of file diff --git a/periphery/dune/plain_crowdsale_cumulative_bids.sql b/periphery/dune/plain_crowdsale_cumulative_bids.sql new file mode 100644 index 00000000..4d071467 --- /dev/null +++ b/periphery/dune/plain_crowdsale_cumulative_bids.sql @@ -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; \ No newline at end of file diff --git a/periphery/tenderly/.gitignore b/periphery/tenderly-actions/.gitignore similarity index 100% rename from periphery/tenderly/.gitignore rename to periphery/tenderly-actions/.gitignore diff --git a/periphery/tenderly/dune.js b/periphery/tenderly-actions/dune.ts similarity index 62% rename from periphery/tenderly/dune.js rename to periphery/tenderly-actions/dune.ts index b5a3576b..339423c0 100755 --- a/periphery/tenderly/dune.js +++ b/periphery/tenderly-actions/dune.ts @@ -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) { diff --git a/periphery/tenderly/package-lock.json b/periphery/tenderly-actions/package-lock.json similarity index 68% rename from periphery/tenderly/package-lock.json rename to periphery/tenderly-actions/package-lock.json index e789e1c2..93aa5b8a 100644 --- a/periphery/tenderly/package-lock.json +++ b/periphery/tenderly-actions/package-lock.json @@ -1,19 +1,22 @@ { - "name": "@moleculeprotocol/web3-actions", + "name": "tenderly-actions", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@moleculeprotocol/web3-actions", + "name": "tenderly-actions", "dependencies": { - "@tenderly/actions": "^0.2.0", - "axios": "^1.4.0" + "@tenderly/actions": "^0.2.57", + "axios": "^1.7.7" + }, + "devDependencies": { + "typescript": "^4.3.5" } }, "node_modules/@tenderly/actions": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/@tenderly/actions/-/actions-0.2.4.tgz", - "integrity": "sha512-3shZek2f8D9qBAGYO1ZT/N5y9HSMNZdGh9R+FS7gv48xm53X3SYqHpqituTda0I/AUABaeD1ZQyFEBOTbsHt0Q==" + "version": "0.2.77", + "resolved": "https://registry.npmjs.org/@tenderly/actions/-/actions-0.2.77.tgz", + "integrity": "sha512-Wnrq5h0fGmVRGlLh+UgIHZynx3Q+1pFiKhTdCQ/Wce3AdEOE73K1WCdXhZrBchAba9y+GqqpF9E25AO++4jI3g==" }, "node_modules/asynckit": { "version": "0.4.0", @@ -21,11 +24,11 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/axios": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", - "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", "dependencies": { - "follow-redirects": "^1.15.0", + "follow-redirects": "^1.15.6", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } @@ -50,9 +53,9 @@ } }, "node_modules/follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", "funding": [ { "type": "individual", @@ -69,9 +72,9 @@ } }, "node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", + "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -104,6 +107,19 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, + "node_modules/typescript": { + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } } } } diff --git a/periphery/tenderly-actions/package.json b/periphery/tenderly-actions/package.json new file mode 100755 index 00000000..58943bd8 --- /dev/null +++ b/periphery/tenderly-actions/package.json @@ -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 +} diff --git a/periphery/tenderly/tsconfig.json b/periphery/tenderly-actions/tsconfig.json similarity index 93% rename from periphery/tenderly/tsconfig.json rename to periphery/tenderly-actions/tsconfig.json index cb5301c2..3dd096ee 100755 --- a/periphery/tenderly/tsconfig.json +++ b/periphery/tenderly-actions/tsconfig.json @@ -5,6 +5,7 @@ "noImplicitReturns": true, "noUnusedLocals": true, "outDir": "out", + "rootDir": "", "sourceMap": true, "strict": true, "target": "es2020" diff --git a/periphery/tenderly.yaml b/periphery/tenderly.yaml index 719c549a..8b199e61 100644 --- a/periphery/tenderly.yaml +++ b/periphery/tenderly.yaml @@ -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 diff --git a/periphery/tenderly/package.json b/periphery/tenderly/package.json deleted file mode 100755 index 6922e3ca..00000000 --- a/periphery/tenderly/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "@moleculeprotocol/web3-actions", - "private": true, - "scripts": {}, - "dependencies": { - "@tenderly/actions": "^0.2.0", - "axios": "^1.4.0" - } -}