Skip to content

Commit

Permalink
devop: add telos
Browse files Browse the repository at this point in the history
  • Loading branch information
kvhnuke committed Jul 23, 2024
1 parent f4a1b37 commit 9896d91
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/extension/src/libs/keyring/public-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class PublicKeyRing {
private async getKeysObject(): Promise<{ [key: string]: EnkryptAccount }> {
const allKeys = await this.#keyring.getKeysObject();
if (process.env.IS_DEV) {
allKeys["0x99999990d598b918799f38163204bbc30611b6b6"] = {
address: "0x99999990d598b918799f38163204bbc30611b6b6",
allKeys["0x339d413ccefd986b1b3647a9cfa9cbbe70a30749"] = {
address: "0x339d413ccefd986b1b3647a9cfa9cbbe70a30749",
basePath: "m/44'/60'/1'/0",
name: "fake account #1",
pathIndex: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import EtherscanActivity from "./providers/etherscan";
import OkcActivity from "./providers/okc";
import TomoScan from "./providers/tomoscan";
import OntEVMActivity from "./providers/ont-evm";
import TelosActivity from "./providers/telos";
export {
RivetActivity,
EtherscanActivity,
OkcActivity,
OntEVMActivity,
TomoScan,
TelosActivity,
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { NetworkNames } from "@enkryptcom/types";

const NetworkEndpoints: Record<string, string> = {
[NetworkNames.Ethereum]: "https://api.etherscan.io/",
[NetworkNames.Ethereum]: "https://eth.blockscout.com/",
[NetworkNames.Binance]: "https://api.bscscan.com/",
[NetworkNames.Matic]: "https://api.polygonscan.com/",
[NetworkNames.Matic]: "https://polygon.blockscout.com/",
[NetworkNames.Moonbeam]: "https://api-moonbeam.moonscan.io/",
[NetworkNames.Moonriver]: "https://api-moonriver.moonscan.io/",
[NetworkNames.KaruraEVM]: "https://blockscout.karura.network/",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NetworkNames } from "@enkryptcom/types";

const NetworkEndpoints: Record<string, string> = {
[NetworkNames.Telos]: "https://api.teloscan.io/",
};

export { NetworkEndpoints };
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import cacheFetch from "@/libs/cache-fetch";
import { EvmNetwork } from "@/providers/ethereum/types/evm-network";
import {
Activity,
ActivityStatus,
ActivityType,
EthereumRawInfo,
} from "@/types/activity";
import { BaseNetwork } from "@/types/base-network";
import { numberToHex } from "web3-utils";
import { decodeTx } from "../../../transaction/decoder";
import { NetworkEndpoints } from "./configs";
import { TelosTXType } from "./types";
const TTL = 30000;
const getAddressActivity = async (
address: string,
endpoint: string
): Promise<EthereumRawInfo[]> => {
return cacheFetch(
{
url: `${endpoint}v1/address/${address}/transactions`,
},
TTL
).then((res) => {
if (!res.success) return [];
const results = res.results as TelosTXType[];
const newResults = results.map((tx) => {
const rawTx: EthereumRawInfo = {
blockHash: "0x",
blockNumber: numberToHex(tx.blockNumber),
contractAddress: tx.contractAddress
? tx.contractAddress.toLowerCase()
: null,
data: tx.input,
effectiveGasPrice: tx.gasPrice,
from: tx.from.toLowerCase(),
to: tx.to === "" ? null : tx.to.toLowerCase(),
gas: tx.gasLimit,
gasUsed: tx.gasused,
nonce: numberToHex(tx.nonce),
status: tx.status === "0x1" ? true : false,
transactionHash: tx.hash,
value: tx.value,
timestamp: tx.timestamp,
};
return rawTx;
});
return newResults.slice(0, 50) as EthereumRawInfo[];
});
};
export default async (
network: BaseNetwork,
address: string
): Promise<Activity[]> => {
address = address.toLowerCase();
const enpoint =
NetworkEndpoints[network.name as keyof typeof NetworkEndpoints];
const activities = await getAddressActivity(address, enpoint);
const Promises = activities.map((activity) => {
return decodeTx(activity, network as EvmNetwork).then((txData) => {
return {
from: activity.from,
to: activity.contractAddress
? activity.contractAddress
: txData.tokenTo!,
isIncoming: activity.from !== address,
network: network.name,
rawInfo: activity,
status: activity.status
? ActivityStatus.success
: ActivityStatus.failed,
timestamp: activity.timestamp ? activity.timestamp : 0,
value: txData.tokenValue,
transactionHash: activity.transactionHash,
type: ActivityType.transaction,
nonce: activity.nonce,
token: {
decimals: txData.tokenDecimals,
icon: txData.tokenImage,
name: txData.tokenName,
symbol: txData.tokenSymbol,
price: txData.currentPriceUSD.toString(),
},
};
});
});
return Promise.all(Promises);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export interface TelosTXType {
gasused: string;
contractAddress: string;
index: number;
nonce: number;
input: string;
gasLimit: string;
blockNumber: number;
from: string;
to: string;
value: string;
hash: string;
timestamp: number;
gasPrice: string;
status: "0x1" | "0x0";
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ const supportedNetworks: Record<SupportedNetworkNames, SupportedNetwork> = {
tbName: "rollux",
cgPlatform: CoingeckoPlatform.Rollux,
},
[NetworkNames.Telos]: {
tbName: "tlos",
cgPlatform: CoingeckoPlatform.Telos,
},
};

const getTokens = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const TokenList: Record<SupportedNetworkNames, string> = {
[NetworkNames.TomoChain]: `https://tokens.coingecko.com/${CoingeckoPlatform.TomoChain}/all.json`,
[NetworkNames.Shibarium]: `https://tokens.coingecko.com/${CoingeckoPlatform.Shibarium}/all.json`,
[NetworkNames.Rollux]: `https://tokens.coingecko.com/${CoingeckoPlatform.Rollux}/all.json`,
[NetworkNames.Telos]: `https://tokens.coingecko.com/${CoingeckoPlatform.Telos}/all.json`,
};

const getKnownNetworkTokens = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ export type SupportedNetworkNames =
| NetworkNames.MaticZK
| NetworkNames.Celo
| NetworkNames.ZkSync
| NetworkNames.Telos
| NetworkNames.Rollux;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions packages/extension/src/providers/ethereum/networks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import syscoinNode from "./sys";
import rolluxTestNode from "./trlx";
import rolluxNode from "./rlx";
import cagaAnkara from "./cagaAnkara";
import telosNode from "./tlos";

export default {
sepolia: sepoliaNode,
Expand Down Expand Up @@ -89,4 +90,5 @@ export default {
rolluxTest: rolluxTestNode,
rollux: rolluxNode,
cagaAnkara: cagaAnkara,
telos: telosNode,
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const rootstockTestnetOptions: EvmNetworkOptions = {
name_long: "Rootstock Testnet",
homePage: "https://rootstock.io/",
blockExplorerTX: "https://explorer.testnet.rootstock.io/tx/[[txHash]]",
blockExplorerAddr: "https://explorer.testnet.rootstock.io/address/[[address]]",
blockExplorerAddr:
"https://explorer.testnet.rootstock.io/address/[[address]]",
chainID: "0x1f",
isTestNetwork: true,
currencyName: "tRBTC",
Expand Down
27 changes: 27 additions & 0 deletions packages/extension/src/providers/ethereum/networks/tlos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CoingeckoPlatform, NetworkNames } from "@enkryptcom/types";
import { EvmNetwork, EvmNetworkOptions } from "../types/evm-network";
import assetsInfoHandler from "@/providers/ethereum/libs/assets-handlers/assetinfo-mew";
import { TelosActivity } from "../libs/activity-handlers";
import wrapActivityHandler from "@/libs/activity-state/wrap-activity-handler";

const ethOptions: EvmNetworkOptions = {
name: NetworkNames.Telos,
name_long: "Telos EVM",
homePage: "https://www.telos.net",
blockExplorerTX: "https://www.teloscan.io/tx/[[txHash]]",
blockExplorerAddr: "https://www.teloscan.io/address/[[address]]",
chainID: "0x28",
isTestNetwork: false,
currencyName: "TLOS",
currencyNameLong: "Telos",
node: "wss://telos.drpc.org",
icon: require("./icons/telos.svg"),
coingeckoID: "telos",
coingeckoPlatform: CoingeckoPlatform.Telos,
assetsInfoHandler,
activityHandler: wrapActivityHandler(TelosActivity),
};

const eth = new EvmNetwork(ethOptions);

export default eth;
2 changes: 2 additions & 0 deletions packages/types/src/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export enum NetworkNames {
RolluxTest = "TRLX",
Rollux = "RLX",
CagaAnkara = "CagaAnkara",
Telos = "TLOS"
}

export enum CoingeckoPlatform {
Expand Down Expand Up @@ -114,4 +115,5 @@ export enum CoingeckoPlatform {
Kadena = "kadena",
Syscoin = "syscoin",
Rollux = "rollux",
Telos = "telos"
}

1 comment on commit 9896d91

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.