From b6c46909cbc6e7ffee7b1cb389bd878e1054a6de Mon Sep 17 00:00:00 2001 From: Corey Rice Date: Fri, 6 Dec 2024 12:14:04 -0300 Subject: [PATCH] refactor: save baseAsset as Token entity --- subgraphs/protocol-reserve/schema.graphql | 2 +- subgraphs/protocol-reserve/src/operations/create.ts | 11 ++++++----- .../tests/ConverterNetwork/index.test.ts | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/subgraphs/protocol-reserve/schema.graphql b/subgraphs/protocol-reserve/schema.graphql index 9ea11641..f6824d95 100644 --- a/subgraphs/protocol-reserve/schema.graphql +++ b/subgraphs/protocol-reserve/schema.graphql @@ -36,7 +36,7 @@ type TokenConverter @entity { address: Bytes! converterNetwork: ConverterNetwork destinationAddress: Bytes! - baseAsset: Bytes! + baseAsset: Token! configs: [TokenConverterConfig!]! @derivedFrom(field: "tokenConverter") paused: Boolean! priceOracleAddress: Bytes! diff --git a/subgraphs/protocol-reserve/src/operations/create.ts b/subgraphs/protocol-reserve/src/operations/create.ts index e036b125..75dab124 100644 --- a/subgraphs/protocol-reserve/src/operations/create.ts +++ b/subgraphs/protocol-reserve/src/operations/create.ts @@ -37,13 +37,14 @@ export function createTokenConverter(tokenConverterAddress: Address): TokenConve if (tokenConverterAddress.equals(riskFundConverterAddress)) { const riskFund = RiskFund.bind(riskFundAddress); - tokenConverter.baseAsset = valueOrNotAvailableAddressIfReverted( - riskFund.try_convertibleBaseAsset(), - ); + const baseAsset = valueOrNotAvailableAddressIfReverted(riskFund.try_convertibleBaseAsset()); + + tokenConverter.baseAsset = getOrCreateToken(Address.fromBytes(baseAsset)).id; } else { - tokenConverter.baseAsset = valueOrNotAvailableAddressIfReverted( + const baseAsset = (tokenConverter.baseAsset = valueOrNotAvailableAddressIfReverted( tokenConverterContract.try_baseAsset(), - ); + )); + tokenConverter.baseAsset = getOrCreateToken(Address.fromBytes(baseAsset)).id; } tokenConverter.priceOracleAddress = valueOrNotAvailableAddressIfReverted( tokenConverterContract.try_priceOracle(), diff --git a/subgraphs/protocol-reserve/tests/ConverterNetwork/index.test.ts b/subgraphs/protocol-reserve/tests/ConverterNetwork/index.test.ts index 9917df38..b6c689bd 100644 --- a/subgraphs/protocol-reserve/tests/ConverterNetwork/index.test.ts +++ b/subgraphs/protocol-reserve/tests/ConverterNetwork/index.test.ts @@ -3,7 +3,7 @@ import { assert, beforeAll, describe, test } from 'matchstick-as/assembly/index' import { handleConverterAdded, handleConverterRemoved } from '../../src/mappings/converterNetwork'; import { getConverterNetworkId, getTokenConverterId } from '../../src/utilities/ids'; -import { createTokenConverterMock } from '../TokenConverter/mocks'; +import { createTokenConverterMock, createTokenMock } from '../TokenConverter/mocks'; import { createConverterAddedEvent, createConverterRemovedEvent } from './events'; const converterNetworkAddress = Address.fromString('0x0000000000000000000000000000000000000ccc'); @@ -27,6 +27,7 @@ beforeAll(() => { token1Address, priceOracleAddress, ); + createTokenMock(token1Address, 'BNB'); }); describe('Converter Network', () => {