Skip to content

Commit

Permalink
Merge pull request #1977 from G-Gamja/main
Browse files Browse the repository at this point in the history
Add GIthub Action(erc20_okx)
  • Loading branch information
wannabit-yongjoo authored Oct 29, 2024
2 parents 55d6908 + df621f3 commit da522b9
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/evm_okx.yml
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 병합 후 브랜치 삭제
2 changes: 2 additions & 0 deletions _script/evm_okx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
package-lock.json
85 changes: 85 additions & 0 deletions _script/evm_okx/evm_okx.mjs
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();
10 changes: 10 additions & 0 deletions _script/evm_okx/package.json
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"
}

0 comments on commit da522b9

Please sign in to comment.