Skip to content

Commit

Permalink
refactor: return data key value from query result
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Dec 1, 2024
1 parent 3fbdb0b commit 74aab50
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 306 deletions.
14 changes: 7 additions & 7 deletions subgraphs/isolated-pools/subgraph-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ class SubgraphClient {
if (result.error) {
console.error(result.error);
}
return result;
return result.data;
}

async getPools(): Promise<PoolsQuery> {
const result = await this.query(PoolsDocument, {});
return result.data;
return result;
}

async getPool(id: string) {
Expand All @@ -58,7 +58,7 @@ class SubgraphClient {

async getMarketById(id: string): Promise<MarketByIdQuery> {
const result = await this.query(MarketByIdDocument, { id });
return result.data;
return result;
}

async getAccountById(id: string) {
Expand All @@ -77,7 +77,7 @@ class SubgraphClient {
first: string;
skip: string;
});
return result.data;
return result;
}

async getMarketActions() {
Expand Down Expand Up @@ -109,7 +109,7 @@ class SubgraphClient {
first: string;
skip: string;
});
return result.data;
return result;
}

async getAccountVTokensWithBorrowByMarketId(
Expand All @@ -126,7 +126,7 @@ class SubgraphClient {
first: string;
skip: string;
});
return result.data;
return result;
}

async getAccountVTokenByAccountAndMarket({
Expand All @@ -139,7 +139,7 @@ class SubgraphClient {
const result = await this.query(AccountVTokenByAccountAndMarketDocument, {
id: `${marketId}${accountId.replace('0x', '')}`,
});
return result.data || { accountVToken: null };
return result || { accountVToken: null };
}

async getAccountPositions(id: string) {
Expand Down
4 changes: 2 additions & 2 deletions subgraphs/isolated-pools/tests/integration/checkEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export const checkMarket = async (marketAddress: string) => {
const vToken = await ethers.getContractAt('VToken', marketAddress);
const comptroller = await ethers.getContractAt('Comptroller', await vToken.comptroller());
const { accountVTokens: accountVTokensSupply } =
await subgraphClient.getAccountVTokensWithSupplyByMarketId(marketAddress.toLowerCase());
await subgraphClient.getAccountVTokensWithSupplyByMarketId(marketAddress.toLowerCase(), 1);
const { accountVTokens: accountVTokensBorrow } =
await subgraphClient.getAccountVTokensWithBorrowByMarketId(marketAddress.toLowerCase());
await subgraphClient.getAccountVTokensWithBorrowByMarketId(marketAddress.toLowerCase(), 1);
const { market } = await subgraphClient.getMarketById(marketAddress.toLowerCase());
expect(market?.supplierCount).to.equal(accountVTokensSupply.length.toString());
expect(market?.borrowerCount).to.equal(accountVTokensBorrow.length.toString());
Expand Down
51 changes: 17 additions & 34 deletions subgraphs/isolated-pools/tests/integration/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ describe('Pools', function () {

it('handles MarketAdded event', async function () {
// check markets
const { data: marketsData } = await subgraphClient.getMarkets();
const { markets } = marketsData!;
const { markets } = await subgraphClient.getMarkets();

expect(markets.length).to.equal(9);

Expand All @@ -29,8 +28,7 @@ describe('Pools', function () {
});

it('handles NewCloseFactor event', async function () {
const { data: dataBeforeUpdate } = await subgraphClient.getPools();
const { pools: poolsBeforeUpdate } = dataBeforeUpdate!;
const { pools: poolsBeforeUpdate } = await subgraphClient.getPools();

expect(poolsBeforeUpdate[0].closeFactorMantissa).to.equal('50000000000000000');

Expand All @@ -40,15 +38,13 @@ describe('Pools', function () {
await tx.wait(1);
await waitForSubgraphToBeSynced(syncDelay);

const { data } = await subgraphClient.getPools();
const { pools } = data!;
const { pools } = await subgraphClient.getPools();

expect(pools[0].closeFactorMantissa).to.equal('600000000000000000');
});

it('handles NewCollateralFactor event', async function () {
const { data: dataBeforeEvent } = await subgraphClient.getMarkets();
const { markets: marketsBeforeEvent } = dataBeforeEvent!;
const { markets: marketsBeforeEvent } = await subgraphClient.getMarkets();
const market = marketsBeforeEvent[1];
const poolLens = await ethers.getContract('PoolLens');
const vTokenMetadata = await poolLens.vTokenMetadata(market.id);
Expand Down Expand Up @@ -80,8 +76,7 @@ describe('Pools', function () {
});

it('handles NewLiquidationIncentive event', async function () {
const { data: dataBeforeEvent } = await subgraphClient.getPools();
const { pools: poolsBeforeEvent } = dataBeforeEvent!;
const { pools: poolsBeforeEvent } = await subgraphClient.getPools();

expect(poolsBeforeEvent[0].liquidationIncentiveMantissa).to.equal('1000000000000000000');

Expand All @@ -91,8 +86,7 @@ describe('Pools', function () {
await tx.wait(1);
await waitForSubgraphToBeSynced(syncDelay);

const { data } = await subgraphClient.getPools();
const { pools } = data!;
const { pools } = await subgraphClient.getPools();

expect(pools[0].liquidationIncentiveMantissa).to.equal('3000000000000000000');
// reset
Expand All @@ -101,8 +95,7 @@ describe('Pools', function () {

it('handles NewPriceOracle event', async function () {
const newPriceOracle = '0x0000000000000000000000000000000000000123';
const { data } = await subgraphClient.getPools();
const { pools } = data!;
const { pools } = await subgraphClient.getPools();

const priceOracle = await ethers.getContract('ResilientOracle');

Expand All @@ -114,31 +107,27 @@ describe('Pools', function () {
await tx.wait(1);
await waitForSubgraphToBeSynced(syncDelay);

const { data: updatedPoolData } = await subgraphClient.getPools();
const { pools: updatedPools } = await subgraphClient.getPools();

const { pools: updatedPools } = updatedPoolData!;
expect(updatedPools[0].priceOracleAddress).to.equal(newPriceOracle);
// Reset oracle address
await comptrollerProxy.setPriceOracle(priceOracle.address);
});

it('handles ActionPausedMarket event', async function () {
const { data: dataBeforeEvent } = await subgraphClient.getMarketActions();
const { marketActions: marketActionsBeforeEvent } = dataBeforeEvent!;
const { marketActions: marketActionsBeforeEvent } = await subgraphClient.getMarketActions();

expect(marketActionsBeforeEvent.length).to.be.equal(0);

const { data: marketsData } = await subgraphClient.getMarkets();
const { markets } = marketsData!;
const { markets } = await subgraphClient.getMarkets();
const market = markets[1];
const comptrollerProxy = await ethers.getContractAt('Comptroller', market.pool.id);

const tx = await comptrollerProxy.setActionsPaused([market.id], [1], true);
await tx.wait(1);
await waitForSubgraphToBeSynced(4000);

const { data } = await subgraphClient.getMarketActions();
const { marketActions } = data!;
const { marketActions } = await subgraphClient.getMarketActions();

expect(marketActions.length).to.be.equal(1);
marketActions.forEach(ma => {
Expand All @@ -151,8 +140,7 @@ describe('Pools', function () {
});

it('handles NewBorrowCap event', async function () {
const { data } = await subgraphClient.getMarkets();
const { markets: marketsBeforeUpdate } = data!;
const { markets: marketsBeforeUpdate } = await subgraphClient.getMarkets();

const poolLens = await ethers.getContract('PoolLens');
let vTokenMetadata = await poolLens.vTokenMetadata(marketsBeforeUpdate[0].id);
Expand All @@ -167,16 +155,14 @@ describe('Pools', function () {
await tx.wait(1);
await waitForSubgraphToBeSynced(syncDelay);

const { data: marketsData } = await subgraphClient.getMarkets();
const { markets } = marketsData!;
const { markets } = await subgraphClient.getMarkets();

vTokenMetadata = await poolLens.vTokenMetadata(marketsBeforeUpdate[0].id);
expect(markets[0].borrowCapMantissa).to.equal(vTokenMetadata.borrowCaps.toString());
});

it('handles NewMinLiquidatableCollateral event', async function () {
const { data: dataBeforeUpdate } = await subgraphClient.getPools();
const { pools: poolsBeforeUpdate } = dataBeforeUpdate!;
const { pools: poolsBeforeUpdate } = await subgraphClient.getPools();

expect(poolsBeforeUpdate[0].minLiquidatableCollateralMantissa).to.equal(
'100000000000000000000',
Expand All @@ -188,17 +174,15 @@ describe('Pools', function () {
await tx.wait(1);
await waitForSubgraphToBeSynced(syncDelay);

const { data } = await subgraphClient.getPools();
const { pools } = data!;
const { pools } = await subgraphClient.getPools();

expect(pools[0].minLiquidatableCollateralMantissa).to.equal('200000000000000000000');
// reset
await comptrollerProxy.setMinLiquidatableCollateral('100000000000000000000');
});

it('handles NewSupplyCap event', async function () {
const { data } = await subgraphClient.getMarkets();
const { markets: marketsBeforeUpdate } = data!;
const { markets: marketsBeforeUpdate } = await subgraphClient.getMarkets();

const poolLens = await ethers.getContract('PoolLens');
let vTokenMetadata = await poolLens.vTokenMetadata(marketsBeforeUpdate[0].id);
Expand All @@ -216,8 +200,7 @@ describe('Pools', function () {
await tx.wait(1);
await waitForSubgraphToBeSynced(syncDelay);

const { data: marketsData } = await subgraphClient.getMarkets();
const { markets } = marketsData!;
const { markets } = await subgraphClient.getMarkets();

vTokenMetadata = await poolLens.vTokenMetadata(marketsBeforeUpdate[0].id);
expect(markets[0].supplyCapMantissa).to.equal(vTokenMetadata.supplyCaps.toString());
Expand Down
13 changes: 5 additions & 8 deletions subgraphs/isolated-pools/tests/integration/poolRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ describe('Pool Registry', function () {
});

it('indexes pool registry events', async function () {
const { data } = await subgraphClient.getPools();
const { pools } = data!;
const { pools } = await subgraphClient.getPools();

expect(pools.length).to.equal(2);

Expand All @@ -67,10 +66,9 @@ describe('Pool Registry', function () {

it('updates and returns metadata from the pool', async function () {
const pools = await poolLens.getAllPools(poolRegistry.address);
const { data: dataBeforeUpdate } = await subgraphClient.getPool(
const { pool: poolBeforeUpdate } = await subgraphClient.getPool(
pools[1].comptroller.toLowerCase(),
);
const { pool: poolBeforeUpdate } = dataBeforeUpdate!;
const onChainPool = await poolLens.getPoolByComptroller(
poolRegistry.address,
poolBeforeUpdate.id,
Expand All @@ -96,15 +94,14 @@ describe('Pool Registry', function () {

it('sets the pool name', async function () {
const newName = 'New Pool 1';
const { data: dataBeforeUpdate } = await subgraphClient.getPools();
const { pools: poolsBeforeUpdate } = dataBeforeUpdate!;
const { pools: poolsBeforeUpdate } = await subgraphClient.getPools();

const tx = await poolRegistry.setPoolName(poolsBeforeUpdate[0].id, newName);
await tx.wait(1);
await waitForSubgraphToBeSynced(syncDelay);

const { data } = await subgraphClient.getPools();
const { pools } = await subgraphClient.getPools();

const { pools } = data!;
const pool = pools[0];
expect(pool.name).to.be.equal(newName);
});
Expand Down
12 changes: 6 additions & 6 deletions subgraphs/isolated-pools/tests/integration/vTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,14 @@ describe('VToken events', function () {

await checkMarket(vBnxToken.address);

const {
data: { account: accountBorrower },
} = await subgraphClient.getAccountById(borrower1.address.toLowerCase());
const { account: accountBorrower } = await subgraphClient.getAccountById(
borrower1.address.toLowerCase(),
);
expect(accountBorrower.countLiquidated).to.equal(1);

const {
data: { account: accountLiquidator },
} = await subgraphClient.getAccountById(liquidator1.address.toLowerCase());
const { account: accountLiquidator } = await subgraphClient.getAccountById(
liquidator1.address.toLowerCase(),
);
expect(accountLiquidator.countLiquidator).to.equal(1);

const vBnxMarket = await checkMarket(vBnxToken.address);
Expand Down
4 changes: 1 addition & 3 deletions subgraphs/isolated-pools/tests/scripts/checkMarkets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ const checkMarkets = async (
provider: providers.MulticallProvider,
subgraphClient: ReturnType<typeof createSubgraphClient>,
) => {
const {
data: { markets },
} = await subgraphClient.getMarkets();
const { markets } = await subgraphClient.getMarkets();

for (const market of markets) {
const vTokenContract = new ethers.Contract(market.id, VBep20Abi, provider);
Expand Down
6 changes: 3 additions & 3 deletions subgraphs/venus/subgraph-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SubgraphClient {
if (result.error) {
console.error(result.error);
}
return result;
return result.data;
}

async getComptroller(): Promise<{ comptroller: ComptrollersQuery['comptrollers'][number] }> {
Expand Down Expand Up @@ -78,7 +78,7 @@ class SubgraphClient {
skip: skip as unknown as string,
marketId,
});
return result.data;
return result;
}

async getAccountVTokensWithBorrowByMarketId({
Expand All @@ -95,7 +95,7 @@ class SubgraphClient {
skip: skip as unknown as string,
marketId,
});
return result.data;
return result;
}

async getAccountVTokensByAccountId(accountId: string) {
Expand Down
4 changes: 1 addition & 3 deletions subgraphs/venus/tests/integration/comptroller-after.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ describe('VToken events', function () {
await waitForSubgraphToBeSynced(syncDelay);

for (const market of markets) {
const {
data: { market: unlistedMarket },
} = await subgraphClient.getMarketById(market.toLowerCase());
const { market: unlistedMarket } = await subgraphClient.getMarketById(market.toLowerCase());

expect(unlistedMarket.isListed).to.equal(false);
}
Expand Down
4 changes: 1 addition & 3 deletions subgraphs/venus/tests/integration/comptroller-before.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ describe('VToken events', function () {
await waitForSubgraphToBeSynced(syncDelay);

for (const [idx, market] of markets.entries()) {
const {
data: { market: listedMarket },
} = await subgraphClient.getMarketById(market.toLowerCase());
const { market: listedMarket } = await subgraphClient.getMarketById(market.toLowerCase());

expect(listedMarket.isListed).to.equal(true);
expect(listedMarket.collateralFactorMantissa).to.equal('0');
Expand Down
Loading

0 comments on commit 74aab50

Please sign in to comment.