Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(contract): Switched to 18 decimals #20

Closed
wants to merge 3 commits into from
Closed
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
13 changes: 7 additions & 6 deletions bot/StateRelayerBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ import {
} from './utils/types';

const DENOMINATION = 'USDT';
const DECIMALS = 10;
const DECIMALS = 18;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const transformToEthersBigNumber = (str: string, decimals: number): ethers.BigNumber =>
ethers.BigNumber.from(
new BigNumber(str).multipliedBy(new BigNumber('10').pow(decimals)).integerValue(BigNumber.ROUND_FLOOR).toString(),
new BigNumber(str)
.multipliedBy(new BigNumber('10').pow(decimals))
.integerValue(BigNumber.ROUND_FLOOR)
.toFixed(0)
.toString(),
);

export async function handler(props: StateRelayerHandlerProps): Promise<DFCData | undefined> {
Expand Down Expand Up @@ -71,7 +76,6 @@ export async function handler(props: StateRelayerHandlerProps): Promise<DFCData
secondTokenBalance: transformToEthersBigNumber(currPair.tokenB.reserve, DECIMALS),
rewards: transformToEthersBigNumber(currPair.apr?.reward.toString() ?? '0', DECIMALS),
commissions: transformToEthersBigNumber(currPair.commission, DECIMALS),
decimals: DECIMALS,
},
} as PairData;
}, {} as PairData);
Expand All @@ -88,7 +92,6 @@ export async function handler(props: StateRelayerHandlerProps): Promise<DFCData
DECIMALS,
);
dataVault.activeAuctions = transformToEthersBigNumber(statsData.loan.count.openAuctions.toString(), 0);
dataVault.decimals = DECIMALS;

// Data from Master Nodes
dataMasterNode.totalValueLockedInMasterNodes = transformToEthersBigNumber(
Expand All @@ -98,15 +101,13 @@ export async function handler(props: StateRelayerHandlerProps): Promise<DFCData
dataMasterNode.zeroYearLocked = transformToEthersBigNumber(statsData.masternodes.locked[0].count.toString(), 0);
dataMasterNode.fiveYearLocked = transformToEthersBigNumber(statsData.masternodes.locked[2].count.toString(), 0);
dataMasterNode.tenYearLocked = transformToEthersBigNumber(statsData.masternodes.locked[1].count.toString(), 0);
dataMasterNode.decimals = DECIMALS;

// Get Data from all burns in ecosystem
burnedData.fee = transformToEthersBigNumber(statsData.burned.fee.toString(), DECIMALS);
burnedData.auction = transformToEthersBigNumber(statsData.burned.auction.toString(), DECIMALS);
burnedData.payback = transformToEthersBigNumber(statsData.burned.payback.toString(), DECIMALS);
burnedData.emission = transformToEthersBigNumber(statsData.burned.emission.toString(), DECIMALS);
burnedData.total = transformToEthersBigNumber(statsData.burned.total.toString(), DECIMALS);
burnedData.decimals = DECIMALS;
// Call SC Function to update Data
// Update Dex information
const dexInfoTx = await stateRelayerContract.updateDEXInfo(
Expand Down
14 changes: 12 additions & 2 deletions bot/test-i9n/StateRelayerBot.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('State Relayer Bot Tests', () => {
}

const receivedBurnedInfo = await proxy.getBurnedInfo();
expect(receivedBurnedInfo[1].fee.toString()).toEqual(expectedBurnedInfo.fee);
expect(receivedBurnedInfo[1].fee.toString()).toEqual(expectedBurnedInfo.fee.toString());
expect(receivedBurnedInfo[1].auction.toString()).toEqual(expectedBurnedInfo.auction);
expect(receivedBurnedInfo[1].payback.toString()).toEqual(expectedBurnedInfo.payback);
expect(receivedBurnedInfo[1].emission.toString()).toEqual(expectedBurnedInfo.emission);
Expand All @@ -101,7 +101,17 @@ describe('State Relayer Bot Tests', () => {
expect(dETH[1].secondTokenBalance.toString()).toEqual(Object.values(expectedPairData['dETH-DFI'])[5]);
expect(dETH[1].rewards.toString()).toEqual(Object.values(expectedPairData['dETH-DFI'])[6]);
expect(dETH[1].commissions.toString()).toEqual(Object.values(expectedPairData['dETH-DFI'])[7]);
expect(dETH[1].decimals.toString()).toEqual(Object.values(expectedPairData['dETH-DFI'])[8]);

// Checking the /dex/dex-pair info
const dBTC = await proxy.getDexPairInfo('dBTC-DFI');
expect(dBTC[1].primaryTokenPrice.toString()).toEqual(Object.values(expectedPairData['dBTC-DFI'])[0]);
expect(dBTC[1].volume24H.toString()).toEqual(Object.values(expectedPairData['dBTC-DFI'])[1]);
expect(dBTC[1].totalLiquidity.toString()).toEqual(Object.values(expectedPairData['dBTC-DFI'])[2]);
expect(dBTC[1].APR.toString()).toEqual(Object.values(expectedPairData['dBTC-DFI'])[3]);
expect(dBTC[1].firstTokenBalance.toString()).toEqual(Object.values(expectedPairData['dBTC-DFI'])[4]);
expect(dBTC[1].secondTokenBalance.toString()).toEqual(Object.values(expectedPairData['dBTC-DFI'])[5]);
expect(dBTC[1].rewards.toString()).toEqual(Object.values(expectedPairData['dBTC-DFI'])[6]);
expect(dBTC[1].commissions.toString()).toEqual(Object.values(expectedPairData['dBTC-DFI'])[7]);

// Checking /dex info
const dex = await proxy.getDexInfo();
Expand Down
56 changes: 27 additions & 29 deletions bot/test-i9n/mockData/oceanMockedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,53 +393,51 @@ export const mockedDexPricesData = {

// generated fixtures from mocked data above
export const expectedBurnedInfo = {
fee: '3150155000000000',
auction: '15125273772605500',
payback: '617050581749106000',
emission: '987835495707572000',
total: '3176341557199576000',
fee: '315015500000000000000000',
auction: '1512527377260550000000000',
payback: '61705058174910600000000000',
emission: '98783549570757200000000000',
total: '317634155719957600000000000',
};

export const expectedVaultData = {
noOfVaults: '11424',
totalLoanValue: '848573751950201500',
totalCollateralValue: '1810116718179531000',
totalCollateralizationRatio: '2133130000000',
totalLoanValue: '84857375195020150000000000',
totalCollateralValue: '181011671817953100000000000',
totalCollateralizationRatio: '213313000000000000000',
activeAuctions: '1',
};

export const expectedMasterNodeData = {
totalValueLockedInMasterNodes: '1528620054717725800',
totalValueLockedInMasterNodes: '152862005471772580000000000',
zeroYearLocked: '10636',
fiveYearLocked: '917',
tenYearLocked: '3491',
};

export const expectedDexInfo = {
totalValueLockInPoolPair: '2722816853262795000',
total24HVolume: '600100000000000',
totalValueLockInPoolPair: '272281685326279500000000000',
total24HVolume: '60010000000000000000000',
};
export const expectedPairData = {
'dETH-DFI': {
primaryTokenPrice: '20720393468322',
volume24H: '120000000000000',
totalLiquidity: '256368632406252443',
apr: '1118468743',
firstTokenBalance: '60845440937100',
secondTokenBalance: '246099134373830200',
rewards: '1056525711',
commission: '20000000',
decimals: '10',
primaryTokenPrice: '2072039346832248773200',
volume24H: '12000000000000000000000',
totalLiquidity: '25636863240625244356535793',
apr: '111846874381970730',
firstTokenBalance: '6084544093710000000000',
secondTokenBalance: '24609913437383020000000000',
rewards: '105652571122515230',
commission: '2000000000000000',
},
'dBTC-DFI': {
primaryTokenPrice: '297944817887563',
volume24H: '120010000000000',
totalLiquidity: '1155096854913583376',
apr: '1252417511',
firstTokenBalance: '19065303332500',
secondTokenBalance: '1108826510654014500',
rewards: '1207452297',
commission: '20000000',
decimals: '10',
primaryTokenPrice: '29794481788756354686900',
volume24H: '12001000000000000000000',
totalLiquidity: '115509685491358337662696092',
apr: '125241751184150370',
firstTokenBalance: '1906530333250000000000',
secondTokenBalance: '110882651065401450000000000',
rewards: '120745229762115770',
commission: '2000000000000000',
},
};
6 changes: 1 addition & 5 deletions contracts/StateRelayer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ contract StateRelayer is UUPSUpgradeable, AccessControlUpgradeable {
uint256 private lastUpdatedMasterNodeInfoTimestamp;
uint256 private lastUpdatedDexInfoTimestamp;
uint256 private lastUpdatedBurnedInfoTimestamp;
uint256 constant public decimals = 18;
struct DEXInfo {
uint256 primaryTokenPrice;
uint256 volume24H;
Expand All @@ -21,8 +22,6 @@ contract StateRelayer is UUPSUpgradeable, AccessControlUpgradeable {
// don't know whether we need price of pooled tokens over here
uint256 rewards;
uint256 commissions;
// packed information about the decimals of each variable
uint40 decimals;
}
mapping(string => DEXInfo) private DEXInfoMapping;

Expand All @@ -32,7 +31,6 @@ contract StateRelayer is UUPSUpgradeable, AccessControlUpgradeable {
uint256 totalCollateralValue;
uint256 totalCollateralizationRatio;
uint256 activeAuctions; // integer values, no decimals
uint40 decimals;
}
VaultGeneralInformation public vaultInfo;

Expand All @@ -42,7 +40,6 @@ contract StateRelayer is UUPSUpgradeable, AccessControlUpgradeable {
uint256 payback;
uint256 emission;
uint256 total;
uint40 decimals;
}
BurnedInformation public burnedInformation;

Expand All @@ -51,7 +48,6 @@ contract StateRelayer is UUPSUpgradeable, AccessControlUpgradeable {
uint256 zeroYearLocked; // integer values, no decimals
uint256 fiveYearLocked; // integer values, no decimals
uint256 tenYearLocked; // integer values, no decimals
uint40 decimals;
}

MasterNodeInformation private masterNodeInformation;
Expand Down
19 changes: 0 additions & 19 deletions tests/StateRelayer.data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('State relayer contract data tests', () => {
zeroYearLocked: 101,
fiveYearLocked: 102,
tenYearLocked: 103,
decimals: 10,
};
await expect(stateRelayerProxy.connect(bot).updateMasterNodeInformation(masterNodeData))
.to.emit(stateRelayerProxy, 'UpdateMasterNodeInformation')
Expand All @@ -38,7 +37,6 @@ describe('State relayer contract data tests', () => {
totalCollateralValue: 23432,
totalCollateralizationRatio: 234,
activeAuctions: 23,
decimals: 10,
};
await expect(stateRelayerProxy.connect(bot).updateVaultGeneralInformation(vaultInformationData))
.to.emit(stateRelayerProxy, 'UpdateVaultGeneralInformation')
Expand All @@ -60,7 +58,6 @@ describe('State relayer contract data tests', () => {
secondTokenBalance: 2314,
rewards: 124,
commissions: 3,
decimals: 18,
};
const dexDataBtc: DexInfo = {
primaryTokenPrice: 112,
Expand All @@ -71,7 +68,6 @@ describe('State relayer contract data tests', () => {
secondTokenBalance: 2312,
rewards: 123,
commissions: 2,
decimals: 18,
};
const dexsData: DexInfo[] = [dexDataEth, dexDataBtc];
const symbols: string[] = ['eth', 'btc'];
Expand All @@ -96,7 +92,6 @@ describe('State relayer contract data tests', () => {
payback: 61705058,
emission: 98783549,
total: 317634155,
decimals: 10,
};
await stateRelayerProxy.connect(bot).updateBurnInfo(burnInfo);
const receivedBurnedData = await stateRelayerProxy.getBurnedInfo();
Expand All @@ -115,7 +110,6 @@ describe('State relayer contract data tests', () => {
zeroYearLocked: 101,
fiveYearLocked: 102,
tenYearLocked: 103,
decimals: 10,
};
await expect(stateRelayerProxy.connect(user).updateMasterNodeInformation(masterNodeData)).to.be.reverted;
});
Expand All @@ -128,7 +122,6 @@ describe('State relayer contract data tests', () => {
totalCollateralValue: 23432,
totalCollateralizationRatio: 234,
activeAuctions: 23,
decimals: 10,
};
await expect(stateRelayerProxy.connect(user).updateVaultGeneralInformation(vaultInformationData)).to.be.reverted;
});
Expand All @@ -145,7 +138,6 @@ describe('State relayer contract data tests', () => {
secondTokenBalance: 2314,
rewards: 124,
commissions: 3,
decimals: 18,
};
await expect(stateRelayerProxy.connect(user).updateDEXInfo(['eth'], [dexDataEth], 1, 2)).to.be.reverted;
});
Expand All @@ -158,7 +150,6 @@ describe('State relayer contract data tests', () => {
payback: 61705058,
emission: 98783549,
total: 317634155,
decimals: 10,
};
await expect(stateRelayerProxy.connect(user).updateBurnInfo(burnInfo)).to.reverted;
});
Expand All @@ -173,7 +164,6 @@ describe('State relayer contract data tests', () => {
zeroYearLocked: 101,
fiveYearLocked: 102,
tenYearLocked: 103,
decimals: 18,
};
const stateRelayerInterface = StateRelayer__factory.createInterface();
const callDataForUpdatingMasterNodeData = stateRelayerInterface.encodeFunctionData(
Expand All @@ -187,7 +177,6 @@ describe('State relayer contract data tests', () => {
totalCollateralValue: 23432,
totalCollateralizationRatio: 234,
activeAuctions: 23,
decimals: 18,
};
const callDataForUpdatingVaultInformation = stateRelayerInterface.encodeFunctionData(
'updateVaultGeneralInformation',
Expand All @@ -204,7 +193,6 @@ describe('State relayer contract data tests', () => {
secondTokenBalance: 2314,
rewards: 124,
commissions: 3,
decimals: 18,
};
const dexDataBtc: DexInfo = {
primaryTokenPrice: 112,
Expand All @@ -215,7 +203,6 @@ describe('State relayer contract data tests', () => {
secondTokenBalance: 2312,
rewards: 123,
commissions: 2,
decimals: 18,
};
const dexsData: DexInfo[] = [dexDataEth, dexDataBtc];
const symbols: string[] = ['eth', 'btc'];
Expand All @@ -233,7 +220,6 @@ describe('State relayer contract data tests', () => {
payback: 34676234,
emission: 23546454,
total: 243563434,
decimals: 18,
};

const callDataBurnedInfo = stateRelayerInterface.encodeFunctionData('updateBurnInfo', [burnedData]);
Expand Down Expand Up @@ -270,7 +256,6 @@ describe('State relayer contract data tests', () => {
zeroYearLocked: 101,
fiveYearLocked: 102,
tenYearLocked: 103,
decimals: 10,
};
const stateRelayerInterface = StateRelayer__factory.createInterface();
const callDataForUpdatingMasterNodeData = stateRelayerInterface.encodeFunctionData(
Expand Down Expand Up @@ -332,7 +317,6 @@ interface MasterNode {
zeroYearLocked: BigNumber;
fiveYearLocked: BigNumber;
tenYearLocked: BigNumber;
decimals: BigNumber;
}

interface VaultGeneralInformation {
Expand All @@ -341,7 +325,6 @@ interface VaultGeneralInformation {
totalCollateralValue: BigNumber;
totalCollateralizationRatio: BigNumber;
activeAuctions: BigNumber;
decimals: BigNumber;
}

interface DexInfo {
Expand All @@ -353,7 +336,6 @@ interface DexInfo {
secondTokenBalance: BigNumber;
rewards: BigNumber;
commissions: BigNumber;
decimals: BigNumber;
}

interface BurnedInfo {
Expand All @@ -362,5 +344,4 @@ interface BurnedInfo {
payback: number;
emission: number;
total: number;
decimals: number;
}