-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1977 from G-Gamja/main
Add GIthub Action(erc20_okx)
- Loading branch information
Showing
4 changed files
with
154 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: EVM OKX Merge | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
jobs: | ||
create-pull-request: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "22" | ||
registry-url: https://registry.npmjs.org/ | ||
|
||
- name: Install dependencies | ||
run: | | ||
npm install --prefix _script/evm_okx | ||
- name: Set environment variables | ||
run: | | ||
echo "OKX_API_KEY=${{ secrets.OKX_API_KEY }}" >> $GITHUB_ENV | ||
echo "OKX_SECRET_KEY=${{ secrets.OKX_SECRET_KEY }}" >> $GITHUB_ENV | ||
echo "OKX_PASSPHRASE=${{ secrets.OKX_PASSPHRASE }}" >> $GITHUB_ENV | ||
- name: Run code modification script | ||
run: | | ||
node _script/evm_okx/evm_okx.mjs cronos 25 | ||
env: | ||
API_KEY: ${{ secrets.OKX_API_KEY }} | ||
SECRET_KEY: ${{ secrets.OKX_SECRET_KEY }} | ||
PASSPHRASE: ${{ secrets.OKX_PASSPHRASE }} | ||
|
||
- name: Create dynamic branch name | ||
id: vars | ||
run: | | ||
BRANCH_NAME="update-assets-$(date +%Y%m%d%H%M%S)" | ||
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT | ||
- name: Create Pull Request | ||
uses: peter-evans/create-pull-request@v7 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
commit-message: "Automated code modification" | ||
branch: ${{ steps.vars.outputs.branch_name }} | ||
title: "Automated PR: Weekly evm assets modification with OKX" | ||
body: "cronos" | ||
draft: false | ||
delete-branch: true # PR 병합 후 브랜치 삭제 |
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,2 @@ | ||
node_modules/ | ||
package-lock.json |
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,85 @@ | ||
import { readFileSync, writeFileSync } from "fs"; | ||
import cryptoJS from "crypto-js"; | ||
|
||
const nativeCoinContractAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; | ||
|
||
async function main() { | ||
try { | ||
const apiKey = process.env.OKX_API_KEY; | ||
const secretKey = process.env.OKX_SECRET_KEY; | ||
const passphrase = process.env.OKX_PASSPHRASE; | ||
|
||
const date = new Date(); | ||
const timestamp = date.toISOString(); | ||
|
||
const chain = process.argv[2]; | ||
|
||
const chainId = process.argv[3]; | ||
|
||
if (!chain || !chainId) { | ||
throw new Error("Missing chain or chainId"); | ||
} | ||
|
||
const fileName = `./chain/${chain}/erc20_2.json`; | ||
const currentAssets = JSON.parse(readFileSync(fileName, "utf-8")); | ||
|
||
const response = await fetch( | ||
`https://www.okx.com/api/v5/dex/aggregator/all-tokens?chainId=${chainId}`, | ||
{ | ||
headers: { | ||
"OK-ACCESS-KEY": apiKey, | ||
"OK-ACCESS-SIGN": cryptoJS.enc.Base64.stringify( | ||
cryptoJS.HmacSHA256( | ||
timestamp + | ||
"GET" + | ||
`/api/v5/dex/aggregator/all-tokens?chainId=${chainId}`, | ||
secretKey | ||
) | ||
), | ||
"OK-ACCESS-TIMESTAMP": timestamp, | ||
"OK-ACCESS-PASSPHRASE": passphrase, | ||
}, | ||
} | ||
); | ||
|
||
const jsonResponse = await response.json(); | ||
|
||
const erc20Assets = jsonResponse.data; | ||
|
||
const currentAssetContractAddresses = currentAssets.map((asset) => { | ||
return asset.contract.toLowerCase(); | ||
}); | ||
|
||
const assetsToAdd = erc20Assets | ||
.filter((asset) => { | ||
return ( | ||
!currentAssetContractAddresses.includes( | ||
asset.tokenContractAddress.toLowerCase() | ||
) && | ||
asset.tokenContractAddress.toLowerCase() !== | ||
nativeCoinContractAddress.toLowerCase() | ||
); | ||
}) | ||
.map((asset) => ({ | ||
type: "erc20", | ||
contract: asset.tokenContractAddress, | ||
name: asset.tokenName, | ||
symbol: asset.tokenSymbol, | ||
description: asset.tokenSymbol, // NOTE: Temporary | ||
decimals: asset.decimals, | ||
image: asset?.tokenLogoUrl, | ||
coinGeckoId: asset?.coingeckoId || "", | ||
})); | ||
|
||
const mergedAssets = [...currentAssets, ...assetsToAdd]; | ||
|
||
writeFileSync(fileName, JSON.stringify(mergedAssets, null, 4)); | ||
|
||
console.log("Assets added successfully"); | ||
} catch (e) { | ||
console.log(e); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
main(); |
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,10 @@ | ||
{ | ||
"name": "evm-okx-github-action", | ||
"version": "1.0.0", | ||
"description": "evm-okx-github-action", | ||
"type": "module", | ||
"dependencies": { | ||
"crypto-js": "^4.2.0" | ||
}, | ||
"license": "ISC" | ||
} |