-
Notifications
You must be signed in to change notification settings - Fork 28
110 lines (91 loc) · 3.34 KB
/
validate-token-address.yml
File metadata and controls
110 lines (91 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: Validate Token Address
on:
issues:
types: [opened, edited]
jobs:
validate-address:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20
- name: Install ethers.js
run: npm install ethers
- name: Extract address and network
id: extract
uses: actions/github-script@v7
with:
script: |
const body = context.payload.issue.body;
// Extract Network
const networkMatch = body.match(/Network\s*\n\s*(.*)/);
const network = networkMatch ? networkMatch[1].trim() : null;
// Extract Address
const addressMatch = body.match(/Address\s*\n\s*(0x[a-fA-F0-9]{40})/);
const address = addressMatch ? addressMatch[1].trim() : null;
core.setOutput('network', network || '');
core.setOutput('address', address || '');
- name: Validate on-chain address
id: validate
run: |
node -e "
const { ethers } = require('ethers');
const network = '${{ steps.extract.outputs.network }}';
const address = '${{ steps.extract.outputs.address }}';
if (!address) {
console.log('No address provided.');
process.exit(1);
}
const rpcMap = {
MAINNET: 'https://rpc.ankr.com/eth',
GNOSIS_CHAIN: 'https://rpc.gnosischain.com',
ARBITRUM_ONE: 'https://arb1.arbitrum.io/rpc',
BASE: 'https://mainnet.base.org',
POLYGON: 'https://polygon-rpc.com',
AVALANCHE: 'https://api.avax.network/ext/bc/C/rpc',
BNB: 'https://bsc-dataseed.binance.org/',
LENS: ''
};
const rpcUrl = rpcMap[network];
if (!rpcUrl) {
console.log('No RPC for network, skipping check.');
process.exit(0);
}
const provider = new ethers.JsonRpcProvider(rpcUrl);
provider.getCode(address).then(code => {
if (code === '0x') {
console.log('Address not found on chain.');
process.exit(1);
} else {
console.log('Address exists on chain.');
}
}).catch(err => {
console.error('Error checking address:', err);
process.exit(1);
});
"
- name: Add comment and label if invalid
if: failure()
uses: actions/github-script@v7
with:
script: |
const issue_number = context.issue.number;
const address = '${{ steps.extract.outputs.address }}';
const network = '${{ steps.extract.outputs.network }}';
// Add comment
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
body: `⚠️ The address \`${address || 'N/A'}\` does not exist or is invalid on network \`${network || 'N/A'}\`. Please verify.`
});
// Add label
await github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
labels: ['invalid-address']
});