Skip to content

Commit

Permalink
add gaslimit into the function arguments and minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuong Truong committed Sep 28, 2023
1 parent 7d20a34 commit b598748
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
29 changes: 21 additions & 8 deletions bot/StateRelayerBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { ethers } from 'ethers';
import { StateRelayer__factory } from '../generated';
import { tranformPairData, transformDataMasternode, transformDataVault } from './utils/transformData';
import { DataStore, MasterNodeData, StateRelayerHandlerProps, VaultData } from './utils/types';
import { ApiPagedResponse} from '@defichain/whale-api-client'
import { PoolPairData } from '@defichain/whale-api-client/dist/api/poolpairs'
import { ApiPagedResponse } from '@defichain/whale-api-client';
import { PoolPairData } from '@defichain/whale-api-client/dist/api/poolpairs';

const DENOMINATION = 'USDT';
const PAGESIZE = 50;
Expand All @@ -20,14 +20,14 @@ export async function handler(props: StateRelayerHandlerProps): Promise<DFCData
const client = getWhaleClient(urlNetwork, envNetwork);
const statsData = await client.stats.get();

let rawPoolPairData : Array<PoolPairData> = [];
let rawPoolPairData: Array<PoolPairData> = [];
let pagedPoolPairData: ApiPagedResponse<PoolPairData> = await client.poolpairs.list(PAGESIZE);
rawPoolPairData = rawPoolPairData.concat(pagedPoolPairData);
while (pagedPoolPairData.hasNext) {
pagedPoolPairData = await client.paginate(pagedPoolPairData);
rawPoolPairData = rawPoolPairData.concat(pagedPoolPairData);
}

const dexPriceData = await client.poolpairs.listDexPrices(DENOMINATION);

const inputForDexUpdate = tranformPairData(rawPoolPairData, statsData, dexPriceData);
Expand All @@ -38,19 +38,32 @@ export async function handler(props: StateRelayerHandlerProps): Promise<DFCData
// Data from Master Nodes
const dataMasterNode = transformDataMasternode(statsData);

const nonce = await signer.getNonce();
// Call SC Function to update Data
// Update Dex information
const dexInfoTx = await stateRelayerContract.updateDEXInfo(
inputForDexUpdate.dex,
inputForDexUpdate.dexInfo,
inputForDexUpdate.totalValueLocked.toString(),
inputForDexUpdate.total24HVolume.toString(),
inputForDexUpdate.totalValueLocked,
inputForDexUpdate.total24HVolume,
{ nonce: nonce, gasLimit: props.gasUpdateDEX },
);

// Update Master Node information
const masterDataTx = await stateRelayerContract.updateMasterNodeInformation(dataMasterNode);
const masterDataTx = await stateRelayerContract.updateMasterNodeInformation(dataMasterNode, {
nonce: nonce + 1,
gasLimit: props.gasUpdateMaster,
});
// Update Vault general information
const vaultTx = await stateRelayerContract.updateVaultGeneralInformation(dataVault);
const vaultTx = await stateRelayerContract.updateVaultGeneralInformation(dataVault, {
nonce: nonce + 2,
gasLimit: props.gasUpdateVault,
});

console.log('Hash of dex update transaction', dexInfoTx.hash);
console.log('Hash of master update transaction', masterDataTx.hash);
console.log('Hash of vault update transaction', vaultTx.hash);

if (!props.testGasCost) {
return {
dataStore,
Expand Down
8 changes: 6 additions & 2 deletions bot/utils/transformData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ const MAXIMUM_UINT256 = 2n ** 256n - 1n;

const transformToBigInt = (val: BigNumber.Value, decimals: number): bigint => {
const bigNumberVal = new BigNumber(val);
if (bigNumberVal.isNaN() || !bigNumberVal.isFinite()) return MAXIMUM_UINT256;
let res: bigint;
if (bigNumberVal.isNaN() || !bigNumberVal.isFinite()) res = MAXIMUM_UINT256;
else {
const bigIntVal = BigInt(bigNumberVal.multipliedBy(new BigNumber('10').pow(decimals)).toFixed(0, 1));
return bigIntVal < MAXIMUM_UINT256 ? bigIntVal : MAXIMUM_UINT256;
res = bigIntVal < MAXIMUM_UINT256 ? bigIntVal : MAXIMUM_UINT256;
}

if (res === MAXIMUM_UINT256) console.log('Invalid value generated');
return res;
};

export function transformDataVault(statsData: StatsData): VaultData {
Expand Down
3 changes: 3 additions & 0 deletions bot/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ export type StateRelayerHandlerProps = {
envNetwork: EnvironmentNetwork;
contractAddress: string;
signer: ethers.Signer;
gasUpdateDEX?: bigint;
gasUpdateMaster?: bigint;
gasUpdateVault?: bigint;
};
8 changes: 4 additions & 4 deletions scripts/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { verify } from './utils/verify';
// npx truffle dashboard
// npx hardhat run --network truffleDashboard ./scripts/deployment.ts
async function main() {
const stateRelayer = await ethers.deployContract("StateRelayer");
await stateRelayer.deploymentTransaction().wait(5);
const stateRelayer = await ethers.deployContract('StateRelayer');
await stateRelayer.deploymentTransaction()?.wait(5);
const stateRelayerAddress = await stateRelayer.getAddress();
console.log('State relayer Contract address: ', stateRelayerAddress);
console.log('Verifying........');
Expand All @@ -22,8 +22,8 @@ async function main() {
'0x17D6bb95cCF124324995F08204132cdf75048284', // Bot
]);
// Deploying StateRelayerProxy contract
const stateRelayerProxy = await ethers.deployContract("StateRelayerProxy", [stateRelayerAddress, encodedData]);
await stateRelayerProxy.deploymentTransaction().wait(5);
const stateRelayerProxy = await ethers.deployContract('StateRelayerProxy', [stateRelayerAddress, encodedData]);
await stateRelayerProxy.deploymentTransaction()?.wait(5);
const stateRelayerProxyAddress = await stateRelayerProxy.getAddress();
console.log('State relayer proxy address: ', stateRelayerProxyAddress);
console.log('Verifying........');
Expand Down
2 changes: 1 addition & 1 deletion tests/StateRelayer.deployment.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';
import { expect } from 'chai';

import { StateRelayer } from '../generated';
Expand Down

0 comments on commit b598748

Please sign in to comment.