Skip to content
Merged
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
7 changes: 4 additions & 3 deletions packages/client/src/actions/hubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export function hub(
*
* ```ts
* const result = await hubs(client, {
* chainIds: [chainId(1), chainId(137)]
* query: {
* chainIds: [chainId(1), chainId(137)]
* }
* });
* ```
*
Expand All @@ -64,8 +66,7 @@ export function hubs(
* ```ts
* const result = await hubAssets(client, {
* chainId: chainId(1),
* hub: evmAddress('0x123...'), // optional
* user: evmAddress('0x456...'), // optional
* hub: evmAddress('0x123…'),
* });
* ```
*
Expand Down
4 changes: 2 additions & 2 deletions packages/spec/borrow/helper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { AaveClient, Reserve, SupplyRequest } from '@aave/client-next';
import {
bigDecimal,
chainId,
type EvmAddress,
evmAddress,
invariant,
Expand All @@ -10,6 +9,7 @@ import {
type TxHash,
} from '@aave/client-next';
import { reserves, supply } from '@aave/client-next/actions';
import { ETHEREUM_FORK_ID } from '@aave/client-next/test-utils';
import { sendWith } from '@aave/client-next/viem';
import type { WalletClient } from 'viem';

Expand All @@ -31,7 +31,7 @@ export function findReserveToSupply(
query: {
tokens: [
{
chainId: chainId(1),
chainId: ETHEREUM_FORK_ID,
address: token,
},
],
Expand Down
45 changes: 45 additions & 0 deletions packages/spec/misc/__snapshots__/chains.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Aave V4 Chains Scenario > Given a user who wants to list available chains > When listing supported chains with a filter > Then it should return the expected list chains with filter ALL 1`] = `
[
{
"__typename": "Chain",
"chainId": 1,
"explorerUrl": "https://etherscan.io",
"icon": "https://statics.aave.com/ethereum.svg",
"isTestnet": false,
"name": "Ethereum",
"nativeInfo": {
"__typename": "TokenInfo",
"decimals": 18,
"icon": "https://statics.aave.com/ethereum.svg",
"name": "Ether",
"symbol": "ETH",
},
"nativeWrappedToken": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
},
]
`;

exports[`Aave V4 Chains Scenario > Given a user who wants to list available chains > When listing supported chains with a filter > Then it should return the expected list chains with filter MAINNET_ONLY 1`] = `
[
{
"__typename": "Chain",
"chainId": 1,
"explorerUrl": "https://etherscan.io",
"icon": "https://statics.aave.com/ethereum.svg",
"isTestnet": false,
"name": "Ethereum",
"nativeInfo": {
"__typename": "TokenInfo",
"decimals": 18,
"icon": "https://statics.aave.com/ethereum.svg",
"name": "Ether",
"symbol": "ETH",
},
"nativeWrappedToken": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
},
]
`;

exports[`Aave V4 Chains Scenario > Given a user who wants to list available chains > When listing supported chains with a filter > Then it should return the expected list chains with filter TESTNET_ONLY 1`] = `[]`;
151 changes: 151 additions & 0 deletions packages/spec/misc/__snapshots__/hub.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Aave V4 Hub Scenarios > Given a user who wants to list available hubs > When fetching hubs by chain ID(s) > Then it should return the expected data for each hub 1`] = `
{
"__typename": "Hub",
"address": "0x4BB8658261CCF575Cb6148a257BE34b36D3D057f",
"chain": {
"__typename": "Chain",
"chainId": 1,
"explorerUrl": "https://etherscan.io",
"icon": "https://statics.aave.com/ethereum.svg",
"isTestnet": false,
"name": "Ethereum",
"nativeInfo": {
"__typename": "TokenInfo",
"decimals": 18,
"icon": "https://statics.aave.com/ethereum.svg",
"name": "Ether",
"symbol": "ETH",
},
"nativeWrappedToken": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
},
"name": "ISO Stable",
"summary": Any<Object>,
}
`;

exports[`Aave V4 Hub Scenarios > Given a user who wants to list available hubs > When fetching hubs by chain ID(s) > Then it should return the expected data for each hub 2`] = `
{
"__typename": "Hub",
"address": "0x7E7c3EDCa4D39D0aFBD468Dec89cdEaF0AC770d3",
"chain": {
"__typename": "Chain",
"chainId": 1,
"explorerUrl": "https://etherscan.io",
"icon": "https://statics.aave.com/ethereum.svg",
"isTestnet": false,
"name": "Ethereum",
"nativeInfo": {
"__typename": "TokenInfo",
"decimals": 18,
"icon": "https://statics.aave.com/ethereum.svg",
"name": "Ether",
"symbol": "ETH",
},
"nativeWrappedToken": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
},
"name": "Core",
"summary": Any<Object>,
}
`;

exports[`Aave V4 Hub Scenarios > Given a user who wants to list available hubs > When fetching hubs by chain ID(s) > Then it should return the expected data for each hub 3`] = `
{
"__typename": "Hub",
"address": "0xA5f18dFE4f0380b6C40411D7Ddb2c04034276805",
"chain": {
"__typename": "Chain",
"chainId": 1,
"explorerUrl": "https://etherscan.io",
"icon": "https://statics.aave.com/ethereum.svg",
"isTestnet": false,
"name": "Ethereum",
"nativeInfo": {
"__typename": "TokenInfo",
"decimals": 18,
"icon": "https://statics.aave.com/ethereum.svg",
"name": "Ether",
"symbol": "ETH",
},
"nativeWrappedToken": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
},
"name": "ISO Gov",
"summary": Any<Object>,
}
`;

exports[`Aave V4 Hub Scenarios > Given a user who wants to list available hubs > When fetching hubs by tokens) > Then it should return the expected data for each hub 1`] = `
{
"__typename": "Hub",
"address": "0x7E7c3EDCa4D39D0aFBD468Dec89cdEaF0AC770d3",
"chain": {
"__typename": "Chain",
"chainId": 1,
"explorerUrl": "https://etherscan.io",
"icon": "https://statics.aave.com/ethereum.svg",
"isTestnet": false,
"name": "Ethereum",
"nativeInfo": {
"__typename": "TokenInfo",
"decimals": 18,
"icon": "https://statics.aave.com/ethereum.svg",
"name": "Ether",
"symbol": "ETH",
},
"nativeWrappedToken": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
},
"name": "Core",
"summary": Any<Object>,
}
`;

exports[`Aave V4 Hub Scenarios > Given a user who wants to list available hubs > When fetching hubs by tokens) > Then it should return the expected data for each hub 2`] = `
{
"__typename": "Hub",
"address": "0xA5f18dFE4f0380b6C40411D7Ddb2c04034276805",
"chain": {
"__typename": "Chain",
"chainId": 1,
"explorerUrl": "https://etherscan.io",
"icon": "https://statics.aave.com/ethereum.svg",
"isTestnet": false,
"name": "Ethereum",
"nativeInfo": {
"__typename": "TokenInfo",
"decimals": 18,
"icon": "https://statics.aave.com/ethereum.svg",
"name": "Ether",
"symbol": "ETH",
},
"nativeWrappedToken": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
},
"name": "ISO Gov",
"summary": Any<Object>,
}
`;

exports[`Aave V4 Hub Scenarios > Given a user who wants to list available hubs > When fetching hubs by tokens) > Then it should return the expected data for each hub 3`] = `
{
"__typename": "Hub",
"address": "0x4BB8658261CCF575Cb6148a257BE34b36D3D057f",
"chain": {
"__typename": "Chain",
"chainId": 1,
"explorerUrl": "https://etherscan.io",
"icon": "https://statics.aave.com/ethereum.svg",
"isTestnet": false,
"name": "Ethereum",
"nativeInfo": {
"__typename": "TokenInfo",
"decimals": 18,
"icon": "https://statics.aave.com/ethereum.svg",
"name": "Ether",
"symbol": "ETH",
},
"nativeWrappedToken": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
},
"name": "ISO Stable",
"summary": Any<Object>,
}
`;
20 changes: 20 additions & 0 deletions packages/spec/misc/chains.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { assertOk, ChainsFilter } from '@aave/client-next';
import { chains } from '@aave/client-next/actions';
import { client } from '@aave/client-next/test-utils';
import { describe, expect, it } from 'vitest';

describe('Aave V4 Chains Scenario', () => {
describe('Given a user who wants to list available chains', () => {
describe('When listing supported chains with a filter', () => {
const filter = Object.values(ChainsFilter);
it.each(filter)(
'Then it should return the expected list chains with filter %s',
async (filter) => {
const result = await chains(client, filter);
assertOk(result);
expect(result.value).toMatchSnapshot();
},
);
});
});
});
16 changes: 0 additions & 16 deletions packages/spec/misc/chains.todo.ts

This file was deleted.

102 changes: 102 additions & 0 deletions packages/spec/misc/hub.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { assertOk } from '@aave/client-next';
import { hub, hubAssets, hubs } from '@aave/client-next/actions';
import {
client,
ETHEREUM_FORK_ID,
ETHEREUM_USDC_ADDRESS,
ETHEREUM_WETH_ADDRESS,
} from '@aave/client-next/test-utils';
import { describe, expect, it } from 'vitest';
import { assertNonEmptyArray } from '../test-utils';

describe('Aave V4 Hub Scenarios', () => {
describe('Given a user who wants to list available hubs', () => {
describe('When fetching hubs by chain ID(s)', () => {
it('Then it should return the expected data for each hub', async () => {
const result = await hubs(client, {
query: { chainIds: [ETHEREUM_FORK_ID] },
});
assertOk(result);
result.value.forEach((hub) => {
expect(hub).toMatchSnapshot({
summary: expect.any(Object),
});
});
});
});

describe('When fetching hubs by tokens)', () => {
const tokens = [ETHEREUM_USDC_ADDRESS, ETHEREUM_WETH_ADDRESS];

it('Then the list of hubs should contains assets from the query', async () => {
const listHubs = await hubs(client, {
query: {
tokens: tokens.map((token) => ({
address: token,
chainId: ETHEREUM_FORK_ID,
})),
},
});
assertOk(listHubs);

for (const hub of listHubs.value) {
const result = await hubAssets(client, {
chainId: ETHEREUM_FORK_ID,
hub: hub.address,
});
assertOk(result);
const assetsInHub = result.value.map(
(asset) => asset.underlying.address,
);
expect(tokens.some((token) => assetsInHub.includes(token))).toBe(
true,
);
}
});
});
});

describe('Given a user who wants to fetch a single hub', () => {
describe('When fetching a single hub', () => {
it('Then it should return the expected data for the hub', async () => {
const listHubs = await hubs(client, {
query: {
chainIds: [ETHEREUM_FORK_ID],
},
});
assertOk(listHubs);
assertNonEmptyArray(listHubs.value);

const result = await hub(client, {
hub: listHubs.value[0].address,
chainId: ETHEREUM_FORK_ID,
});
assertOk(result);
expect(result.value).toMatchObject(listHubs.value[0]);
});
});
});

describe('Given a user who wants to know assets in a hub', () => {
describe('When fetching assets in a hub', () => {
it('Then it should return the expected data for assets in a hub', async () => {
const listHubs = await hubs(client, {
query: {
chainIds: [ETHEREUM_FORK_ID],
},
});

assertOk(listHubs);
assertNonEmptyArray(listHubs.value);

const result = await hubAssets(client, {
hub: listHubs.value[0].address,
chainId: ETHEREUM_FORK_ID,
});
assertOk(result);
assertNonEmptyArray(result.value);
expect(result.value).toMatchObject(listHubs.value[0]);
});
});
});
});
Loading