Skip to content

Commit

Permalink
fix(data): new l1 subgraph now correctly formats numbers (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
kelonye authored Sep 30, 2021
1 parent 9da6371 commit 7beca44
Show file tree
Hide file tree
Showing 36 changed files with 220 additions and 332 deletions.
6 changes: 3 additions & 3 deletions packages/data/__mocks__/burned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ export const burnedMock = {
id: '0x320e4bcaccb2b445ab8521e8a35e850db8145f29d689c64613e10bc3fc5cffcb-237',
source: 'sUSD',
timestamp: '1614910767',
value: '5954277455094130661333214',
value: '5954277.455094130661333214',
},
formatted: {
account: '0x042ed37d32b88ab6b1c2e7b8a400dcdc728050bc',
block: 11975546,
gasPrice: '127000000000',
gasPrice: 127000000000,
id: '0x320e4bcaccb2b445ab8521e8a35e850db8145f29d689c64613e10bc3fc5cffcb-237',
source: 'sUSD',
timestamp: 1614910767000,
value: '5954277.455094130661333214',
value: 5954277.455094130661333214,
},
};
8 changes: 4 additions & 4 deletions packages/data/__mocks__/dailyBurned.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export const dailyBurnedMock = {
response: {
id: '1627446407',
value: '5954277455094130661333214',
totalDebt: '5954277455094130661333214',
value: '5954277.455094130661333214',
totalDebt: '5954277.455094130661333214',
},
formatted: {
id: '1627446407',
value: '5954277.455094130661333214',
totalDebt: '5954277.455094130661333214',
value: 5954277.455094130661333214,
totalDebt: 5954277.455094130661333214,
},
};
8 changes: 4 additions & 4 deletions packages/data/__mocks__/dailyIssued.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export const dailyIssuedMock = {
response: {
id: '1627446407',
value: '5954277455094130661333214',
totalDebt: '5954277455094130661333214',
value: '5954277.455094130661333214',
totalDebt: '5954277.455094130661333214',
},
formatted: {
id: '1627446407',
value: '5954277.455094130661333214',
totalDebt: '5954277.455094130661333214',
value: 5954277.455094130661333214,
totalDebt: 5954277.455094130661333214,
},
};
12 changes: 6 additions & 6 deletions packages/data/__mocks__/debtSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ export const debtSnapshotMock = {
block: '11975546',
id: '0x320e4bcaccb2b445ab8521e8a35e850db8145f29d689c64613e10bc3fc5cffcb-237',
timestamp: '1614910767',
collateral: '5954277455094130661333214',
debtBalanceOf: '954277455094130661333214',
balanceOf: '4277455094130661333214',
collateral: '5954277.455094130661333214',
debtBalanceOf: '954277.455094130661333214',
balanceOf: '4277.455094130661333214',
},
formatted: {
account: '0x042ed37d32b88ab6b1c2e7b8a400dcdc728050bc',
block: 11975546,
id: '0x320e4bcaccb2b445ab8521e8a35e850db8145f29d689c64613e10bc3fc5cffcb-237',
timestamp: 1614910767000,
collateral: '5954277.455094130661333214',
debtBalanceOf: '954277.455094130661333214',
balanceOf: '4277.455094130661333214',
collateral: 5954277.455094130661333214,
debtBalanceOf: 954277.455094130661333214,
balanceOf: 4277.455094130661333214,
},
};
12 changes: 6 additions & 6 deletions packages/data/__mocks__/exchangeEntrySettleds.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
export const exchangeEntrySettledsMock = {
response: {
amount: '9992880960411389',
amount: '0.009992880960411389',
dest: '0x7355534400000000000000000000000000000000000000000000000000000000',
destRoundIdAtPeriodEnd: '1',
exchangeTimestamp: '1612821588',
from: '0x042ed37d32b88ab6b1c2e7b8a400dcdc728050bc',
id: '0x07ad98b4d27aa3dc80c7505e5cfca1af115d8a7c0421d150ff7c8e7c04cd046b-346',
rebate: '469106080900746546',
rebate: '0.469106080900746546',
reclaim: '0',
src: '0x7342544300000000000000000000000000000000000000000000000000000000',
srcRoundIdAtPeriodEnd: '55340232221128667446',
},
formatted: {
amount: '0.009992880960411389',
amount: 0.009992880960411389,
dest: '0x7355534400000000000000000000000000000000000000000000000000000000',
destRoundIdAtPeriodEnd: '1',
exchangeTimestamp: 1612821588,
exchangeTimestamp: 1612821588000,
from: '0x042ed37d32b88ab6b1c2e7b8a400dcdc728050bc',
id: '0x07ad98b4d27aa3dc80c7505e5cfca1af115d8a7c0421d150ff7c8e7c04cd046b-346',
rebate: '0.469106080900746546',
reclaim: '0.0',
rebate: 0.469106080900746546,
reclaim: 0,
src: '0x7342544300000000000000000000000000000000000000000000000000000000',
srcRoundIdAtPeriodEnd: '55340232221128667446',
},
Expand Down
6 changes: 3 additions & 3 deletions packages/data/__mocks__/exchangeTotals.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const exchangeTotalsMock = {
response: {
totalFeesGeneratedInUSD: '11641102349921181385',
exchangeUSDTally: '7772376002297375000000',
exchangers: '1',
totalFeesGeneratedInUSD: '11.641102349921181385',
exchangeUSDTally: '7772.376002297375',
exchangers: 1,
id: '1723502',
trades: '1',
},
Expand Down
8 changes: 4 additions & 4 deletions packages/data/__mocks__/feesClaimed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ export const feesClaimedMock = {
block: '11975546',
id: '0x320e4bcaccb2b445ab8521e8a35e850db8145f29d689c64613e10bc3fc5cffcb-237',
timestamp: '1614910767',
value: '5954277455094130661333214',
rewards: '954277455094130661333214',
value: '5954277.455094130661333214',
rewards: '954277.455094130661333214',
},
formatted: {
account: '0x042ed37d32b88ab6b1c2e7b8a400dcdc728050bc',
block: 11975546,
id: '0x320e4bcaccb2b445ab8521e8a35e850db8145f29d689c64613e10bc3fc5cffcb-237',
timestamp: 1614910767000,
value: '5954277.455094130661333214',
rewards: '954277.455094130661333214',
value: 5954277.455094130661333214,
rewards: 954277.455094130661333214,
},
};
6 changes: 3 additions & 3 deletions packages/data/__mocks__/issued.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ export const issuedMock = {
id: '0x320e4bcaccb2b445ab8521e8a35e850db8145f29d689c64613e10bc3fc5cffcb-237',
source: 'sUSD',
timestamp: '1614910767',
value: '5954277455094130661333214',
value: '5954277.455094130661333214',
},
formatted: {
account: '0x042ed37d32b88ab6b1c2e7b8a400dcdc728050bc',
block: 11975546,
gasPrice: '127000000000',
gasPrice: 127000000000,
id: '0x320e4bcaccb2b445ab8521e8a35e850db8145f29d689c64613e10bc3fc5cffcb-237',
source: 'sUSD',
timestamp: 1614910767000,
value: '5954277.455094130661333214',
value: 5954277.455094130661333214,
},
};
4 changes: 2 additions & 2 deletions packages/data/__mocks__/rates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ export const ratesMock = {
block: '12110296',
currencyKey: '0x534e580000000000000000000000000000000000000000000000000000000000',
id: '0x2470d3b05f019581cf8df76a522db5c48780ef5dc0118977ba1e45056c4d6072-SNX',
rate: '16480000000000000000',
rate: '16.48',
synth: 'SNX',
timestamp: '1616704370',
},
formatted: {
block: 12110296,
currencyKey: '0x534e580000000000000000000000000000000000000000000000000000000000',
id: '0x2470d3b05f019581cf8df76a522db5c48780ef5dc0118977ba1e45056c4d6072-SNX',
rate: '16.48',
rate: 16.48,
synth: 'SNX',
timestamp: 1616704370000,
},
Expand Down
26 changes: 13 additions & 13 deletions packages/data/__mocks__/snxHolder.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
export const snxHolderMock = {
response: {
balanceOf: '68069683028764',
balanceOf: '0.000068069683028764',
block: '10108119',
claims: null,
collateral: '68069683028764',
debtEntryAtIndex: '1000000000000000000000000000',
claims: '5',
collateral: '0.000068069683028764',
debtEntryAtIndex: '22152845382348635959243347',
id: '0x0000000000000000000000000000000000000001',
initialDebtOwnership: '0',
mints: null,
mints: '6',
timestamp: '1590049259',
transferable: '68069683028764',
transferable: '0.000068069683028764',
},
formatted: {
balanceOf: '0.000068069683028764',
balanceOf: 0.000068069683028764,
block: 10108119,
claims: null,
collateral: '0.000068069683028764',
debtEntryAtIndex: '1000000000.0',
claims: 5,
collateral: 0.000068069683028764,
debtEntryAtIndex: '22152845382348635959243347',
id: '0x0000000000000000000000000000000000000001',
initialDebtOwnership: '0.0',
mints: null,
initialDebtOwnership: 0,
mints: 6,
timestamp: 1590049259000,
transferable: '0.000068069683028764',
transferable: 0.000068069683028764,
},
};
2 changes: 1 addition & 1 deletion packages/data/__mocks__/snxPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export const snxPriceMock = {
},
formatted: {
id: '18712',
averagePrice: '16.48',
averagePrice: 16.48,
},
};
43 changes: 12 additions & 31 deletions packages/data/__mocks__/synthExchanges.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,39 @@
export const synthExchangesMockL1 = {
export const synthExchangesMock = {
response: {
account: '0x60d4f28f407121bca015d47cdc9b9b4546b5a9c7',
block: '12116438',
feesInUSD: '747549034706154047462',
feesInUSD: '747.549034706154047462',
from: '0x0eb59acd1f0b73970e5b2fd095bf373ce569e4a9',
fromAmount: '249183011568718006275302',
fromAmountInUSD: '249183011568718006275302',
fromAmount: '249183.011568718006275302',
fromAmountInUSD: '249183.011568718006275302',
fromCurrencyKey: '0x7355534400000000000000000000000000000000000000000000000000000000',
fromSynth: 'sUSD',
gasPrice: '142100000000',
id: '0x5771afba4755d73e1becf5b58640b48b999b01ac267c4d39334916ee90285088-232',
timestamp: '1616785448',
toAddress: '0x60d4f28f407121bca015d47cdc9b9b4546b5a9c7',
toAmount: '4628088422134899435',
toAmountInUSD: '248435462534011852227840',
toAmount: '4.628088422134899435',
toAmountInUSD: '248435.46253401185222784',
toCurrencyKey: '0x7342544300000000000000000000000000000000000000000000000000000000',
toSynth: 'sBTC',
},
formatted: {
account: '0x60d4f28f407121bca015d47cdc9b9b4546b5a9c7',
block: 12116438,
feesInUSD: '747.549034706154047462',
feesInUSD: 747.549034706154047462,
from: '0x0eb59acd1f0b73970e5b2fd095bf373ce569e4a9',
fromAmount: '249183.011568718006275302',
fromAmountInUSD: '249183.011568718006275302',
fromAmount: 249183.011568718006275302,
fromAmountInUSD: 249183.011568718006275302,
fromCurrencyKey: 'sUSD',
fromSynth: 'sUSD',
gasPrice: '142100000000',
gasPrice: 142100000000,
id: '0x5771afba4755d73e1becf5b58640b48b999b01ac267c4d39334916ee90285088-232',
timestamp: 1616785448000,
toAddress: '0x60d4f28f407121bca015d47cdc9b9b4546b5a9c7',
toAmount: '4.628088422134899435',
toAmountInUSD: '248435.46253401185222784',
toAmount: 4.628088422134899435,
toAmountInUSD: 248435.46253401185222784,
toCurrencyKey: 'sBTC',
toSynth: 'sBTC',
hash: '0x5771afba4755d73e1becf5b58640b48b999b01ac267c4d39334916ee90285088',
},
};

export const synthExchangesMockL2 = {
response: {
...synthExchangesMockL1.response,
fromAmount: '249183.011568718006275302',
toAmount: '4.628088422134899435',
fromAmountInUSD: '249183.011568718006275302',
toAmountInUSD: '248435.462534011852227840',
feesInUSD: '747.549034706154047462',
},
formatted: {
...synthExchangesMockL1.formatted,
fromAmount: '249183.011568718006275302',
toAmount: '4.628088422134899435',
fromAmountInUSD: '249183.01',
toAmountInUSD: '248435.46',
feesInUSD: '747.55',
},
};
2 changes: 1 addition & 1 deletion packages/data/__mocks__/synthHolders.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const synthHoldersMock = {
response: {
balanceOf: '90038854631941946067435170',
balanceOf: '90038854.63194194',
id: '0x6c5024cd4f8a59110119c56f8933403a539555eb-sUSD',
synth: 'sUSD',
},
Expand Down
19 changes: 7 additions & 12 deletions packages/data/__tests__/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
parseIssued,
parseRates,
parseSynthetix,
parseSynthExchangesL1,
parseSynthExchangesL2,
parseSynthExchanges,
parseBurned,
parseFeesClaimed,
parseSnxPrice,
Expand All @@ -29,8 +28,7 @@ import {
ratesMock,
feesClaimedMock,
synthetixMock,
synthExchangesMockL1,
synthExchangesMockL2,
synthExchangesMock,
debtSnapshotMock,
snxHolderMock,
shortsMock,
Expand Down Expand Up @@ -98,12 +96,9 @@ describe('@synthetixio/data tests', () => {
});

describe('exchanges query', () => {
test('should parse the response correctly for L1 and L2', () => {
const parsedOutputL1 = parseSynthExchangesL1(synthExchangesMockL1.response);
expect(synthExchangesMockL1.formatted).toEqual(parsedOutputL1);

const parsedOutputL2 = parseSynthExchangesL2(synthExchangesMockL2.response);
expect(synthExchangesMockL2.formatted).toEqual(parsedOutputL2);
test('should parse the response correctly', () => {
const parsedOutput = parseSynthExchanges(synthExchangesMock.response);
expect(synthExchangesMock.formatted).toEqual(parsedOutput);
});

test('should return exchanges from l1', async () => {
Expand Down Expand Up @@ -375,8 +370,8 @@ describe('@synthetixio/data tests', () => {
expect(exchangeEntrySettleds.length).toEqual(1);
const exchangeEntrySettled = exchangeEntrySettleds[0]!;
expect(exchangeEntrySettled.from).toEqual('0xe51b3d74b9e8203b5e817e691a5d0d7f00898fbd');
expect(exchangeEntrySettled.reclaim).toEqual('150.57812586144');
expect(exchangeEntrySettled.rebate).toEqual('0.0');
expect(exchangeEntrySettled.reclaim).toEqual(150.57812586144);
expect(exchangeEntrySettled.rebate).toEqual(0);
});
});

Expand Down
6 changes: 3 additions & 3 deletions packages/data/queries/burned/parse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Burned } from '../../generated/graphql';
import { formatTimestamp, formatEther } from '../../src/utils';
import { formatTimestamp } from '../../src/utils';

export const parseBurned = ({
account,
Expand All @@ -12,9 +12,9 @@ export const parseBurned = ({
}: Burned): Burned => ({
account,
block: Number(block),
gasPrice,
gasPrice: Number(gasPrice),
id,
source,
timestamp: formatTimestamp(timestamp),
value: formatEther(value),
value: Number(value),
});
2 changes: 1 addition & 1 deletion packages/data/queries/dailyBurned/dailyBurned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const createDailyBurnedQuery = (params?: DailyBurnedQueryParams): string
) {
id
value
totalDebt
totalDebt
}
}
`;
Expand Down
5 changes: 2 additions & 3 deletions packages/data/queries/dailyBurned/parse.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { DailyBurned } from '../../generated/graphql';
import { formatEther } from '../../src/utils';

export const parseDailyBurned = ({ id, value, totalDebt }: DailyBurned): DailyBurned => ({
id,
value: formatEther(value),
totalDebt: formatEther(totalDebt),
value: Number(value),
totalDebt: Number(totalDebt),
});
Loading

0 comments on commit 7beca44

Please sign in to comment.