Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] node: Governor token list update #3587

Closed
68 changes: 68 additions & 0 deletions .github/workflows/governor-token-list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Governor Token List Update
on:
pull_request: # TODO: remove this before merging. just for debugging
schedule:
- cron: '0 0 15 * *' # Run at 00:00 on the 15th of every month

permissions:
contents: write
pull-requests: write

jobs:
token-list-update:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v2
with:
go-version: "1.20.10"
- uses: actions/setup-node@v2
with:
node-version: "16"
- name: Generate new token list
run: |
cd node/hack/governor
npm ci
npm run start
- name: Verify new token list
run: |
cd node/hack/governor
go run check_query.go
- name: Run Governor tests
run: |
cd node/pkg/governor
go test
# - name: Checkout main
# run: git checkout main
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
message: "node: governor token list update"
new_branch: node/governor-token-list-update

# - name: Read changes.txt file
# id: changes
# working-directory: "./node/hack/governor"
# run: echo "::set-output name=changes::$(cat changes.txt)"
- name: Create Pull Request
env:
GITHUB_TOKEN: ${{ secrets.GOVERNOR_TOKEN_LIST_UPDATE_SECRET }}
run: |
gh pr create \
--repo wormhole-foundation/wormhole \
--base main \
--draft \
--head djb15:node/governor-token-list-update \
--title "node: Governor token list update" \
--body-file ./node/hack/governor/changes.txt

# - name: Create Pull Request
# uses: peter-evans/create-pull-request@v5.0.2
# with:
# commit-message: "node: governor token list update"
# body: ${{ steps.changes.outputs.changes }}
# title: 'node: Governor token list update'
# branch: node/governor-token-list-update
# base: main
# delete-branch: true
# draft: true
3 changes: 2 additions & 1 deletion node/hack/governor/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lib
node_modules
node_modules
changes.txt
82 changes: 81 additions & 1 deletion node/hack/governor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Connection, JsonRpcProvider } from "@mysten/sui.js";
import { arrayify, zeroPad } from "ethers/lib/utils";

const MinNotional = 0;
const PriceDeltaTolerance = 30; // Price change tolerance in %

const axios = require("axios");
const fs = require("fs");
Expand Down Expand Up @@ -48,6 +49,21 @@ if (fs.existsSync(IncludeFileName)) {
},
*/

// Get the existing token list to check for any extreme price changes and removed tokens
var existingTokenPrices = {};
var existingTokenKeys: string[] = [];
var newTokenKeys = {};

fs.readFile("../../pkg/governor/generated_mainnet_tokens.go", "utf8", function(_, doc) {
var matches = doc.matchAll(/{chain: (?<chain>[0-9]+).+addr: "(?<addr>[0-9a-fA-F]+)".*symbol: "(?<symbol>.*)", coin.*price: (?<price>.*)}.*\n/g);
for(let result of matches) {
let {chain, addr, symbol, price} = result.groups;
if (!existingTokenPrices[chain]) existingTokenPrices[chain] = {};
existingTokenPrices[chain][addr] = parseFloat(price);
existingTokenKeys.push(chain + "-" + addr + "-" + symbol);
}
});

axios
.get(
"https://europe-west3-wormhole-message-db-mainnet.cloudfunctions.net/tvl"
Expand All @@ -73,6 +89,11 @@ axios
content += "func generatedMainnetTokenList() []tokenConfigEntry {\n";
content += "\treturn []tokenConfigEntry {\n";

var significantPriceChanges = [];
var addedTokens = [];
var removedTokens = [];
var newTokensCount = 0;

for (let chain in res.data.AllTime) {
for (let addr in res.data.AllTime[chain]) {
if (addr !== "*") {
Expand Down Expand Up @@ -141,6 +162,34 @@ axios
}
}

// This is a new token
if (!existingTokenPrices[chain][wormholeAddr]) {
addedTokens.push(chain + "-" + wormholeAddr + "-" + data.Symbol);
}
// This is an existing token
else {
var previousPrice = existingTokenPrices[chain][wormholeAddr];

// Price has increased by > tolerance
if (data.TokenPrice > previousPrice * ((100 + PriceDeltaTolerance) / 100)) {
significantPriceChanges.push({
token: chain + "-" + wormholeAddr + "-" + data.Symbol,
previousPrice: previousPrice,
newPrice: data.TokenPrice,
percentageChange: (notional / previousPrice) * 100
});
}
// Price has decreased by > tolerance
else if (data.TokenPrice < previousPrice - (previousPrice * (PriceDeltaTolerance / 100))){
significantPriceChanges.push({
token: chain + "-" + wormholeAddr + "-" + data.Symbol,
previousPrice: previousPrice,
newPrice: data.TokenPrice,
percentageChange: 100 - (notional / previousPrice) * 100
});
}
}

content +=
"\t{ chain: " +
chain +
Expand All @@ -160,12 +209,43 @@ axios
notional +
"\n";

//console.log("chain: " + chain + ", addr: " + data.Address + ", symbol: " + data.Symbol + ", notional: " + notional + ", price: " + data.TokenPrice + ", amount: " + data.Amount)
newTokenKeys[chain + "-" + wormholeAddr + "-" + data.Symbol] = true;
newTokensCount += 1;
}
}
}
}

for (var token of existingTokenKeys) {
// A token has been removed from the token list
if (!newTokenKeys[token]) {
removedTokens.push(token);
}
}

// Sanity check to make sure the script is doing what we think it is
if (existingTokenKeys.length + addedTokens.length - removedTokens.length != newTokensCount) {
console.error("The new number of tokens doesn't make sense");
process.exit(1);
}

var changedContent = "Tokens before = " + existingTokenKeys.length;
changedContent += "\nTokens after = " + newTokensCount;
changedContent += "\n\nTokens added = " + addedTokens.length + ":\n\n";
changedContent += JSON.stringify(addedTokens, null, 1);
changedContent += "\n\nTokens removed = " + removedTokens.length + ":\n\n";
changedContent += JSON.stringify(removedTokens, null, 1);
changedContent += "\n\nTokens with significant price changes (>" + PriceDeltaTolerance + "%) = " + significantPriceChanges.length + ":\n\n"
changedContent += JSON.stringify(significantPriceChanges, null, 1);

await fs.writeFileSync(
"./changes.txt",
changedContent,
{
flag: "w+",
}
);

content += "\t}\n";
content += "}\n";

Expand Down
Loading
Loading