Skip to content

Commit

Permalink
refactor: save baseAsset as Token entity
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Dec 6, 2024
1 parent 0020ab4 commit b6c4690
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion subgraphs/protocol-reserve/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
11 changes: 6 additions & 5 deletions subgraphs/protocol-reserve/src/operations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -27,6 +27,7 @@ beforeAll(() => {
token1Address,
priceOracleAddress,
);
createTokenMock(token1Address, 'BNB');
});

describe('Converter Network', () => {
Expand Down

0 comments on commit b6c4690

Please sign in to comment.