Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Data Service for Spark Protocol BOS Component
# Data Service for Aave v3 Protocol BOS Components

This service aggregates data from Spark Protocol across multiple chains, providing a crucial link between Spark Lend and applications that wish to utilize its data. [Spark Lend](https://github.com/marsfoundation/sparklend) is a lending market based on the Aave v3 codebase, that is currently live on Gnosis and Ethereum.
This service aggregates data from the Aave v3 Protocol across multiple chains, providing a crucial link between the [Aave lending market](https://github.com/aave) and applications that wish to utilize its data.

This Data Service was initially developed to be used in conjugation with [Spark Nexus](https://github.com/Deepcryptodive/spark-nexus), but it can also be run stand-alone.
This Data Service was initially developed to be used in conjugation with [Spark Nexus](https://github.com/Deepcryptodive/spark-nexus), but it can also be run stand-alone. Note that in the current `aave-nexus` branch, Spark Protocol is not supported - only Aave v3.

## Features

- Aggregates and serves market data from Spark Lend.
- Aggregates and serves market data from Aave v3
- Provides user-specific deposit, debt, and health factor information.
- Supports multiple blockchains (i.e. where Spark Protocol is deployed)
- Supports multiple blockchains (i.e. where Aave v3 is deployed)
- Is accesible as public API

## Getting Started

You can deploy this locally, or have it run on Cloudflare.
We have deployed it at `https://spark-api.pages.dev/`
We have deployed it at `https://aave-nexus.pages.dev/`

### Prerequisites

Expand All @@ -35,13 +35,18 @@ Before running the service locally, ensure you have the following installed:
Deploy the service to Cloudflare Pages with the `yarn deploy` command.

Ensure you have the correct permissions and environmental variables set up.
i.e. in the [Cloudflare Dashboard]([url](https://dash.cloudflare.com/)), under `Workers & Pages` create a Page with name `spark-api` (or which name you defined in `package.json`). You **do not** need to link it to the Github repo.
i.e. in the [Cloudflare Dashboard]([url](https://dash.cloudflare.com/)), under `Workers & Pages` create a Page with name `aave-nexus` (or which name you defined in `package.json`). You **do not** need to link it to the Github repo.

## Support Chains (chainID)

- Ethereum Mainnet (1)
- Optimism (10)
- Gnosis (100)
- _For debuggin purposes only:_ Polygon Mainnet (137) (fetching data from Aave v3 on Polygon)
- Polygon (137)
- Metis (1088)
- Base (8453)
- Arbitrum (42161)
- Avalanche (43114)

## API endpoints

Expand All @@ -51,7 +56,7 @@ i.e. in the [Cloudflare Dashboard]([url](https://dash.cloudflare.com/)), under `
- Get all available Spark Lend markets
- `chainId`: Spark Lend supported chain ID

Example query: https://spark-api.pages.dev/100/markets
Example query: https://aave-nexus.pages.dev/100/markets

Example local query: http://localhost:8080/100/markets

Expand All @@ -62,7 +67,7 @@ i.e. in the [Cloudflare Dashboard]([url](https://dash.cloudflare.com/)), under `
- `chainId`: Spark Lend supported chain ID
- `user`: user address

Example query: https://spark-api.pages.dev/100/deposits/0xca4aD39F872E89Ef23eABd5716363Fc22513E147
Example query: https://aave-nexus.pages.dev/100/deposits/0xca4aD39F872E89Ef23eABd5716363Fc22513E147

Example local query: http://localhost:8080/100/deposits/0xca4aD39F872E89Ef23eABd5716363Fc22513E147

Expand All @@ -73,7 +78,7 @@ i.e. in the [Cloudflare Dashboard]([url](https://dash.cloudflare.com/)), under `
- `chainId`: Spark Lend supported chain ID
- `user`: user address

Example query: https://spark-api.pages.dev/100/debts/0xca4aD39F872E89Ef23eABd5716363Fc22513E147
Example query: https://aave-nexus.pages.dev/100/debts/0xca4aD39F872E89Ef23eABd5716363Fc22513E147

Example local query: http://localhost:8080/100/debts/0xca4aD39F872E89Ef23eABd5716363Fc22513E147

Expand All @@ -87,7 +92,7 @@ i.e. in the [Cloudflare Dashboard]([url](https://dash.cloudflare.com/)), under `
- `amount`: token USD value
- `asset`: token address

Example query: https://spark-api.pages.dev/100/health/0xca4aD39F872E89Ef23eABd5716363Fc22513E147?action=deposit&amount=10&asset=0xe91d153e0b41518a2ce8dd3d7944fa863463a97d
Example query: https://aave-nexus.pages.dev/100/health/0xca4aD39F872E89Ef23eABd5716363Fc22513E147?action=deposit&amount=10&asset=0xe91d153e0b41518a2ce8dd3d7944fa863463a97d

Example local query: http://localhost:8080/100/health/0xca4aD39F872E89Ef23eABd5716363Fc22513E147?action=deposit&amount=10&asset=0xe91d153e0b41518a2ce8dd3d7944fa863463a97d

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start:prod": "node dist/app/app.js",
"start:wrangler": "yarn wrangler pages dev ./",
"build": "tsc",
"deploy": "yarn wrangler pages deploy ./ --project-name spark-api --env production",
"deploy": "yarn wrangler pages deploy ./ --project-name aave-nexus --env production",
"prepare": "husky install"
},
"devDependencies": {
Expand All @@ -27,9 +27,9 @@
"wrangler": "^3.0.1"
},
"dependencies": {
"@aave/contract-helpers": "^1.17.6",
"@aave/math-utils": "^1.17.6",
"@bgd-labs/aave-address-book": "^1.24.0",
"@aave/contract-helpers": "^1.21.0",
"@aave/math-utils": "^1.21.0",
"@bgd-labs/aave-address-book": "^2.11.0",
"@cloudflare/workers-types": "^4.20230518.0",
"@koa/cors": "^4.0.0",
"bignumber.js": "^9.1.1",
Expand Down
96 changes: 87 additions & 9 deletions utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,105 @@ export const chainConfig: {
walletBalanceProvider: string;
};
} = {
//Aave v3 on Arbitrum
[ChainId.arbitrum_one]: {
providerRPC: "https://arbitrum.llamarpc.com",
uiPoolDataProviderAddress: markets.AaveV3Arbitrum.UI_POOL_DATA_PROVIDER,
lendingPoolAddressProvider: markets.AaveV3Arbitrum.POOL_ADDRESSES_PROVIDER,
walletBalanceProvider: markets.AaveV3Arbitrum.WALLET_BALANCE_PROVIDER,
},
//Aave v3 on Mainnet
[ChainId.mainnet]: {
providerRPC: "https://eth.llamarpc.com",
uiPoolDataProviderAddress: markets.AaveV3Ethereum.UI_POOL_DATA_PROVIDER,
lendingPoolAddressProvider: markets.AaveV3Ethereum.POOL_ADDRESSES_PROVIDER,
walletBalanceProvider: markets.AaveV3Ethereum.WALLET_BALANCE_PROVIDER,
},
//Aave v3 on Gnosis - hardcoded chanId since it's not yet update in helper npm package
[100]: {
providerRPC: "https://gnosis.publicnode.com",
uiPoolDataProviderAddress: markets.AaveV3Gnosis.UI_POOL_DATA_PROVIDER,
lendingPoolAddressProvider: markets.AaveV3Gnosis.POOL_ADDRESSES_PROVIDER,
walletBalanceProvider: markets.AaveV3Gnosis.WALLET_BALANCE_PROVIDER,
},
//Aave v3 on Base
[ChainId.base]: {
providerRPC: "https://base.llamarpc.com",
uiPoolDataProviderAddress: markets.AaveV3Base.UI_POOL_DATA_PROVIDER,
lendingPoolAddressProvider: markets.AaveV3Base.POOL_ADDRESSES_PROVIDER,
walletBalanceProvider: markets.AaveV3Base.WALLET_BALANCE_PROVIDER,
},
//Aave v3 on Optimism
[ChainId.optimism]: {
providerRPC: "https://optimism.llamarpc.com",
uiPoolDataProviderAddress: markets.AaveV3Optimism.UI_POOL_DATA_PROVIDER,
lendingPoolAddressProvider: markets.AaveV3Optimism.POOL_ADDRESSES_PROVIDER,
walletBalanceProvider: markets.AaveV3Optimism.WALLET_BALANCE_PROVIDER,
},
//Aave v3 on Polygon
[ChainId.polygon]: {
providerRPC: "https://polygon.llamarpc.com",
uiPoolDataProviderAddress: markets.AaveV3Polygon.UI_POOL_DATA_PROVIDER,
lendingPoolAddressProvider: markets.AaveV3Polygon.POOL_ADDRESSES_PROVIDER,
walletBalanceProvider: markets.AaveV3Polygon.WALLET_BALANCE_PROVIDER,
},

// Unused Aave markets (for now)

//Aave v3 on Metis (1088)
[1088]: {
providerRPC: "https://metis-pokt.nodies.app",
uiPoolDataProviderAddress: markets.AaveV3Metis.UI_POOL_DATA_PROVIDER,
lendingPoolAddressProvider: markets.AaveV3Metis.POOL_ADDRESSES_PROVIDER,
walletBalanceProvider: markets.AaveV3Metis.WALLET_BALANCE_PROVIDER,
},

//Aave v3 on Avalanche (43114)
[ChainId.avalanche]: {
providerRPC: "https://avax-pokt.nodies.app/ext/bc/C/rpc",
uiPoolDataProviderAddress: markets.AaveV3Avalanche.UI_POOL_DATA_PROVIDER,
lendingPoolAddressProvider: markets.AaveV3Avalanche.POOL_ADDRESSES_PROVIDER,
walletBalanceProvider: markets.AaveV3Avalanche.WALLET_BALANCE_PROVIDER,
},

//Aave v3 on Fantom (250) - deprecated
/*
[ChainId.fantom]: {
providerRPC: "https://1rpc.io/ftm ",
uiPoolDataProviderAddress: markets.AaveV3Fantom.UI_POOL_DATA_PROVIDER,
lendingPoolAddressProvider: markets.AaveV3Fantom.POOL_ADDRESSES_PROVIDER,
walletBalanceProvider: markets.AaveV3Fantom.WALLET_BALANCE_PROVIDER,
},
*/

//Aave v3 on Harmony (1666600000) - deprecated
/*
[ChainId.harmony]: {
providerRPC: "https://1rpc.io/ftm ",
uiPoolDataProviderAddress: markets.AaveV3Harmony.UI_POOL_DATA_PROVIDER,
lendingPoolAddressProvider: markets.AaveV3Harmony.POOL_ADDRESSES_PROVIDER,
walletBalanceProvider: markets.AaveV3Harmony.WALLET_BALANCE_PROVIDER,
},
*/

//Hardcoded the addresses of Spark protocol deployments
//No Github 'address book' for Spark Protocol available
/*
[ChainId.mainnet]: {
providerRPC: "https://eth-pokt.nodies.app",
providerRPC: "https://eth.llamarpc.com",
uiPoolDataProviderAddress: "0xF028c2F4b19898718fD0F77b9b881CbfdAa5e8Bb",
lendingPoolAddressProvider: "0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE",
walletBalanceProvider: "0xd2AeF86F51F92E8e49F42454c287AE4879D1BeDc",
},
[100]: {
providerRPC: "https://gnosis-pokt.nodies.app",
providerRPC: "https://gnosis.publicnode.com",
uiPoolDataProviderAddress: "0xF028c2F4b19898718fD0F77b9b881CbfdAa5e8Bb",
lendingPoolAddressProvider: "0xA98DaCB3fC964A6A0d2ce3B77294241585EAbA6d",
walletBalanceProvider: "0xd2AeF86F51F92E8e49F42454c287AE4879D1BeDc",
},
//Keep for debugging purposes - This relates to Aave v3 on Polygon
[ChainId.polygon]: {
providerRPC: "https://rpc.ankr.com/polygon",
uiPoolDataProviderAddress: markets.AaveV3Polygon.UI_POOL_DATA_PROVIDER,
lendingPoolAddressProvider: markets.AaveV3Polygon.POOL_ADDRESSES_PROVIDER,
walletBalanceProvider: markets.AaveV3Polygon.WALLET_BALANCE_PROVIDER,
},
*/


};

export function getTimestamp() {
Expand Down
63 changes: 50 additions & 13 deletions utils/permit_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,61 @@ import { ChainId } from "@aave/contract-helpers";
export const permitByChainAndToken: {
[chainId: number]: Record<string, boolean>;
} = {
[ChainId.arbitrum_one]: {
"0xf97f4df75117a78c1a5a0dbb814af92458539fb4": true,
"0xff970a61a04b1ca14834a43f5de4533ebddb5cc8": true,
"0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f": true,
"0x82af49447d8a07e3bd95bd0d56f35241523fbab1": true,
"0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9": true,
"0xba5ddd1f9d7f570dc94a51479a000e3bce967196": true,
"0xd22a58f79e9481d1a88e00c343885a588b34b68b": false, // eurs
},

[ChainId.mainnet]: {
"0x6b175474e89094c44da98b954eedeac495271d0f": false,
"0x83f20f44975d03b1b09e64809b757c47f942beea": false,
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": false,
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2": false,
"0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0": false,
"0x6810e776880c02933d47db1b9fc05908e5386b96": false,
"0xae78736cd615f374d3085123a210448e74fc6393": false,
"0xdac17f958d2ee523a2206206994597c13d831ec7": false,
},
//Keep for debugging purposes - This relates to Aave v3 on Polygon
[ChainId.polygon]: {
"0x4e3decbb3645551b8a19f0ea1678079fcb33fb4c": true,
"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599": false,
"0x514910771af9ca656af840dff83e8264ecf986ca": false,
"0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9": true,
"0xbe9895146f7af43049ca1c1ae358b0541ea49704": false,
"0x5f98805a4e8be255a32880fdec7f6728c6568ba0": false,
"0xd533a949740bb3306d119cc777fa900ba034cd52": false,
"0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2": false,
"0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f": false,
"0xba100000625a3754423978a60c9317c58a424e3d": false,
"0x1f9840a85d5af5bf1d1762f925bdaddc4201f984": false,
"0x5a98fcbea516cf06857215779fd812ca3bef1b32": false,
"0xc18360217d8f7ab5e7c516566761ea12ce7f9d72": false,
"0x111111111117dc0aa78b770fa6a738034120c302": false,
"0x853d955acef822db058eb8505911ed77f175b99e": false,
"0x40d16fc0246ad3160ccc09b8d0d3a2cd28ae6c2f": false,
"0xd33526068d116ce69f19a9ee46f0bd304f21a51f": false,
"0xaf5191b0de278c7286d6c7cc6ab6bb8a73ba2cd6": false,
"0xdefa4e8a7bcba345f687a2f1456f5edd9ce97202": false,
},

[100]: {
"0xe91d153e0b41518a2ce8dd3d7944fa863463a97d": false,
"0x6a023ccd1ff6f2045c3309768ead9e68f978f6e1": false,
"0x6c76971f98945ae98dd7d4dfca8711ebea946ea6": false,
"0x9c58bacc331c9aa871afd802db6379a98e80cedb": false,
"0xddafbb505ad214d7b80b1f830fccc89b60fb7a83": false,
"0xe91d153e0b41518a2ce8dd3d7944fa863463a97d": false,
"0xcb444e90d8198415266c6a2724b7900fb12fc56e": false,
"0xaf204776c7245bf4147c2612bf6e5972ee483701": false,
},

[ChainId.base]: {
},

[ChainId.optimism]: {
},

[ChainId.polygon]: {
"0x4e3decbb3645551b8a19f0ea1678079fcb33fb4c": true,
},

[1088]: {
},

[ChainId.avalanche]: {
},

};