Skip to content

Commit

Permalink
evm support
Browse files Browse the repository at this point in the history
  • Loading branch information
mrq1911 committed Dec 10, 2023
1 parent a7bf809 commit c5333db
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start:rococo": "RPC_URL=wss://hydradx-rococo-rpc.play.hydration.cloud npm run start",
"start:mainnet": "USD_TOKEN=2 RPC_URL=wss://rpc.basilisk.cloud npm run start",
"start:test": "USD_TOKEN=2 NODE_ENV=test RPC_URL=wss://rpc.basilisk.cloud npm run start",
"start:test:omnipool": "USD_TOKEN=2 NODE_ENV=test WHALE_AMOUNT=100000000 RPC_URL=wss://hydradx-rpc.dwellir.com npm run start"
"start:test:omnipool": "USD_TOKEN=2 NODE_ENV=test WHALE_AMOUNT=100000000 RPC_URL=wss://rpc.hydradx.cloud npm run start"
},
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async function main() {
if (process.env.NODE_ENV === 'test') {
console.log('testing mode: pushing testing blocks');
const blockNumbers = new Set([]);
blockNumbers.add(4012925);
blockNumbers.add(3640483);
blockNumbers.add(3640479);
blockNumbers.add(3640440);
Expand Down
5 changes: 4 additions & 1 deletion src/currencies.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {api} from "./api.js";
import dijkstrajs from "dijkstrajs";
import {usdCurrencyId, whaleAmount} from "./config.js";
import {fromAccount} from "./utils/evm.js";

let currencies = {};

Expand Down Expand Up @@ -75,7 +76,9 @@ export const decimals = currencyId => {
return currency.decimals || 12;
}

export const formatAccount = (address, whale, icon = `🐍`) => (whale ? 'πŸ‹' : icon) + `\`${address.toString().substr(-3)}\``;
const short = address => (fromAccount(address.toString()) || address.toString()).substr(-3);

export const formatAccount = (address, whale, icon = `🐍`) => (whale ? 'πŸ‹' : icon) + `\`${short(address)}\``;
export const formatAmount = ({amount, currencyId}) => new Intl.NumberFormat('en-US', {maximumSignificantDigits: 4})
.format(Number(amount) / 10 ** decimals(currencyId)).replace(/,/g, " ") + ' ' + symbol(currencyId);
export const formatUsdValue = value => {
Expand Down
23 changes: 23 additions & 0 deletions src/utils/evm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { decodeAddress } from "@polkadot/util-crypto";

const prefixBytes = Buffer.from("ETH\0");

export function isEvmAccount(address) {
if (!address) return false;

try {
const pub = decodeAddress(address, true);
return Buffer.from(pub.subarray(0, prefixBytes.length)).equals(prefixBytes);
} catch {
return false;
}
}

export function fromAccount(address) {
if (!isEvmAccount(address)) {
return null;
}
const decodedBytes = decodeAddress(address);
const addressBytes = decodedBytes.slice(prefixBytes.length, -8);
return Buffer.from(addressBytes).toString("hex");
}

0 comments on commit c5333db

Please sign in to comment.