Skip to content

Commit

Permalink
Reorganizing assets into separate JSON files
Browse files Browse the repository at this point in the history
  • Loading branch information
pgbrandao committed Nov 26, 2023
1 parent d7f2958 commit ed98591
Show file tree
Hide file tree
Showing 6 changed files with 1,683 additions and 1,656 deletions.
27 changes: 23 additions & 4 deletions core/src/transaction/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { BigNumberish, Provider, getAddress } from "ethers";
import { getPricesAndLinkedAssets } from "./get-prices-and-linked-assets";
import { Router } from "core/src/abis";

import path from "path";
import fs from "fs";
export interface Asset {
id: string;
name: string;
Expand Down Expand Up @@ -45,15 +46,33 @@ export class AssetStore {
this.#prices = {};
this.#linkedAssets = {};

const definiteAssets: Asset[] =
assets ?? require("../../../data/assets.json");
const consolidatedAssets = assets ?? this.loadAssets();

definiteAssets.forEach((asset) => {
consolidatedAssets.forEach((asset) => {
this.#byId[asset.id] = asset;
this.#byAddress[asset.address] = asset;
});
}

loadAssets() {
const assetDirPath = path.join(__dirname, "../../../data/assets");
const chainIds = fs.readdirSync(assetDirPath);
let allAssets = [];

for (const chainId of chainIds) {
const protocolDirPath = path.join(assetDirPath, chainId);
const protocolTypes = fs.readdirSync(protocolDirPath);

for (const protocolType of protocolTypes) {
const filePath = path.join(protocolDirPath, protocolType);
const assets = JSON.parse(fs.readFileSync(filePath, "utf8"));
allAssets = allAssets.concat(assets);
}
}

return allAssets;
}

// Function that gets asset by ID, if not found throws an error
getAssetById(assetId: string): Asset {
const asset = this.#byId[assetId];
Expand Down
45 changes: 45 additions & 0 deletions data/assets/137/aaveV3Deposit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[
{
"id": "46062b41-6661-4eae-bc11-4d4ec07b062f",
"active": true,
"address": "0x6d80113e533a2C0fe82EaBD35f1875DcEA89Ea97",
"color": "#468af0",
"decimals": 18,
"linkedAssets": [
{
"assetId": "d604439e-d464-4df5-bed1-66815b348cab",
"fraction": 1
}
],
"name": "Aave Polygon WMATIC",
"chainId": 137,
"symbol": "aPolWMATIC",
"type": "aaveV3Deposit",
"visible": true,
"category": ["Lending", "Yield", "Blue chip"],
"allowSlot": 53,
"balanceSlot": 52,
"maxSize": 40
},
{
"id": "371b83f1-3301-4c69-b3ad-8d199c6d1774",
"active": true,
"address": "0x625e7708f30ca75bfd92586e17077590c60eb4cd",
"color": "#2775ca",
"decimals": 6,
"linkedAssets": [
{
"assetId": "e251ecf6-48c2-4538-afcd-fbb92424054d",
"fraction": 1
}
],
"name": "Aave Polygon USDC",
"chainId": 137,
"symbol": "aPolUSDC",
"type": "aaveV3Deposit",
"visible": true,
"allowSlot": 53,
"balanceSlot": 52,
"maxSize": 40
}
]
57 changes: 57 additions & 0 deletions data/assets/137/balancerDeposit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
{
"id": "03f36f17-bbc2-4d8d-b0b2-9ce0f534d708",
"active": true,
"address": "0x42942cDeC85078Cf0e28e9CB5ACd40CB53997Ed6",
"callParams": {
"poolId": "0x42942cdec85078cf0e28e9cb5acd40cb53997ed6000000000000000000000bea",
"selfIndex": 1
},
"color": "#049c3c",
"decimals": 18,
"linkedAssets": [
{
"assetId": "90f159bc-b2ef-4251-a24b-a4fa7b5b97fa",
"fraction": 0
},
{
"assetId": "578aa621-59d8-4c4c-ad01-891f50769f4a",
"fraction": 1
}
],
"name": "jBRL/BRZ",
"chainId": 137,
"symbol": "jBRL/BRZ",
"type": "balancerDeposit",
"visible": false,
"allowSlot": 1,
"balanceSlot": 0
},
{
"id": "9b09afe5-c740-4cd7-a247-4fe4950a7f33",
"active": true,
"address": "0xcd78A20c597E367A4e478a2411cEB790604D7c8F",
"callParams": {
"poolId": "0xcd78a20c597e367a4e478a2411ceb790604d7c8f000000000000000000000c22"
},
"color": "#049c3c",
"decimals": 18,
"linkedAssets": [
{
"assetId": "8634b650-20fe-4f9e-8310-6672b38ea0ce",
"fraction": 0
},
{
"assetId": "d604439e-d464-4df5-bed1-66815b348cab",
"fraction": 1
}
],
"name": "maticX/WMATIC",
"chainId": 137,
"symbol": "maticX/WMATIC",
"type": "balancerDeposit",
"visible": false,
"allowSlot": 1,
"balanceSlot": 0
}
]
82 changes: 82 additions & 0 deletions data/assets/137/beefyDeposit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
[
{
"id": "fecfd33d-e6a7-476b-89cb-910a0058fa48",
"name": "beefy.finance",
"chainId": 137,
"active": true,
"address": "0xfEcf784F48125ccb7d8855cdda7C5ED6b5024Cb3",
"color": "#c5bcb0",
"decimals": 18,
"symbol": "BIFI",
"type": "beefyDeposit",
"visible": false,
"allowSlot": 1,
"balanceSlot": 0,
"linkedAssets": [
{
"assetId": "27f50305-72b0-4910-87f7-4b052054e377",
"fraction": 1
}
]
},
{
"id": "7aef4761-daff-4a50-8d56-c3e4393b1c25",
"name": "Gains Network",
"chainId": 137,
"active": true,
"address": "0xf2d0557101bEA0Eb2879151DC08d7a2603588BDe",
"color": "#00D1A8",
"decimals": 18,
"symbol": "GNS",
"type": "beefyDeposit",
"visible": true,
"allowSlot": 52,
"balanceSlot": 51,
"linkedAssets": [
{
"assetId": "170c2077-1b4a-45e4-9a18-8ce371c63db5",
"fraction": 1
}
]
},
{
"id": "e7a63d19-c2c4-491c-b154-4063fe0fb479",
"name": "Quickswap",
"chainId": 137,
"active": true,
"address": "0x659418cc3cf755F5367a51aDb586a7F770Da6d29",
"color": "#408ac9",
"decimals": 18,
"symbol": "QUICK",
"type": "beefyDeposit",
"visible": false,
"allowSlot": 1,
"balanceSlot": 0,
"linkedAssets": [
{
"assetId": "85d42621-43a2-4189-930f-9b1ff0cf74f4",
"fraction": 1
}
]
},
{
"id": "37819023-9c6a-4848-8cf5-24a95350f001",
"name": "Quickswap",
"chainId": 137,
"active": true,
"address": "0x1A723371f9dc30653dafd826B60d9335bf867E35",
"color": "#408ac9",
"decimals": 18,
"symbol": "QUICK",
"type": "beefyDeposit",
"visible": true,
"allowSlot": 1,
"balanceSlot": 0,
"linkedAssets": [
{
"assetId": "d35b7aaf-a2ff-44e0-a3df-cdc702ed71ba",
"fraction": 1
}
]
}
]
Loading

0 comments on commit ed98591

Please sign in to comment.