Skip to content

Commit 7a0e8b1

Browse files
committed
script to fetch xc transaction histroy
1 parent e7b4032 commit 7a0e8b1

File tree

12 files changed

+325
-26
lines changed

12 files changed

+325
-26
lines changed

contracts/_utilities/ChainBridgeBatchRebaseReport.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ contract ChainBridgeBatchRebaseReport {
3333
(epoch, totalSupply) = IPolicy(policy).globalAmpleforthEpochAndAMPLSupply();
3434

3535
uint256 dataLen = 64;
36-
IBridge(bridge).deposit{value:bridgeFee}(
36+
IBridge(bridge).deposit{value: bridgeFee}(
3737
destinationChainID,
3838
resourceID,
3939
abi.encode(dataLen, epoch, totalSupply)

hardhat.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require('./tasks/ops/xc_transfer');
1616
require('./tasks/info/config');
1717
require('./tasks/info/ampl');
1818
require('./tasks/info/chain_bridge');
19+
require('./tasks/info/cb_ampl_tx');
1920

2021
module.exports = {
2122
solidity: {
@@ -90,6 +91,6 @@ module.exports = {
9091
},
9192
prodBscSatChain: {
9293
url: 'https://bsc-dataseed.binance.org/'
93-
},
94+
}
9495
}
9596
};

helpers/contracts.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const { getAdminAddress } = require('@openzeppelin/upgrades-core');
44
const DEPLOYMENT_CONFIG_PATH = __dirname + '/../sdk/deployments';
55
const { getEthersProvider } = require('./utils');
66

7+
const BLOCKS_PER_SEC = 1 / 15;
8+
79
const ContractABIPaths = {
810
// Openzepppelin
911
ProxyAdmin: '@openzeppelin/upgrades/contracts/upgradeability',
@@ -157,6 +159,43 @@ const writeProxyDeploymentData = async (network, contractRef, contract) => {
157159
fs.writeFileSync(addressFile, JSON.stringify(chainAddresses, null, 2));
158160
};
159161

162+
const filterContractEvents = async (
163+
ethers,
164+
provider,
165+
address,
166+
abi,
167+
event,
168+
startBlock,
169+
endBlock,
170+
timeFrameSec = 7 * 24 * 3600,
171+
) => {
172+
endBlock = endBlock || (await provider.getBlockNumber());
173+
const freq = timeFrameSec * BLOCKS_PER_SEC;
174+
175+
let logs = [];
176+
for (let i = startBlock; i <= endBlock; i += freq) {
177+
// console.log(i, startBlock, endBlock)
178+
const _logs = await provider.getLogs({
179+
address: address,
180+
fromBlock: ethers.utils.hexlify(i),
181+
toBlock: ethers.utils.hexlify(i + freq > endBlock ? endBlock : i + freq),
182+
});
183+
logs = logs.concat(_logs);
184+
}
185+
186+
const contractInterface = new ethers.utils.Interface(abi);
187+
const decodedEvents = logs.reduce((m, log) => {
188+
try {
189+
log.parsed = contractInterface.parseLog(log);
190+
log.parsed.name == event ? m.push(log) : m;
191+
return m;
192+
} catch (e) {
193+
return m;
194+
}
195+
}, []);
196+
return decodedEvents;
197+
};
198+
160199
module.exports = {
161200
readDeploymentData,
162201
readContractDeploymentData,
@@ -169,4 +208,6 @@ module.exports = {
169208
deployContract,
170209
deployProxyAdminContract,
171210
deployProxyContract,
211+
212+
filterContractEvents,
172213
};

helpers/tasks.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ const { task } = require('hardhat/config');
44

55
function txTask(name, desc) {
66
return task(name, desc)
7-
.addParam(
8-
'gasPrice',
9-
'Gas price for the transaction',
10-
0,
11-
types.int,
12-
)
7+
.addParam('gasPrice', 'Gas price for the transaction', 0, types.int)
138
.addParam('gasLimit', 'Gas limit for the transaction', 7000000, types.int)
149
.addParam('txSleepSec', 'Time to wait between transactions', 2, types.int)
1510
.addParam('keyfile', 'The path to signer keyfile')

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@openzeppelin/contracts": "^3.2.0",
2222
"@openzeppelin/contracts-upgradeable": "^3.3.0",
2323
"@openzeppelin/upgrades": "^2.8.0",
24-
"chainbridge-solidity": "https://github.com/ChainSafe/chainbridge-solidity#a15727ad30bb359b4dfd0fb155f338d11ea80753",
24+
"chainbridge-solidity": "https://github.com/meterio/chainbridge-solidity-v1.0.0-eth#master",
2525
"market-oracle": "https://github.com/ampleforth/market-oracle#v1.0.1",
2626
"uFragments": "https://github.com/ampleforth/uFragments#v1.1.0"
2727
},
@@ -38,6 +38,7 @@
3838
"bignumber.js": "^9.0.1",
3939
"chai": "^4.2.0",
4040
"commander": "^6.2.1",
41+
"csv-writer": "^1.6.0",
4142
"eslint": "^4.19.1",
4243
"eslint-config-google": "^0.9.1",
4344
"eslint-config-mocha": "^0.0.0",
@@ -66,6 +67,7 @@
6667
"stochasm": "^0.5.0",
6768
"ts-node": "^9.0.0",
6869
"typechain": "^4.0.3",
69-
"typescript": "^4.0.2"
70+
"typescript": "^4.0.2",
71+
"underscore": "^1.13.1"
7072
}
7173
}

sdk/ampleforth.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ const BigNumber = require('bignumber.js');
44
const AMPL_DECIMALS = 9;
55

66
const toAmplFloatingPt = (ample) =>
7-
ethers.utils.formatUnits(`${ample.toFixed ? ample.toFixed(AMPL_DECIMALS) : ample}`, AMPL_DECIMALS);
7+
ethers.utils.formatUnits(
8+
`${ample.toFixed ? ample.toFixed(AMPL_DECIMALS) : ample}`,
9+
AMPL_DECIMALS,
10+
);
811

912
const toAmplFixedPt = (ample) =>
10-
ethers.utils.parseUnits(`${ample.toFixed ? ample.toFixed(AMPL_DECIMALS) : ample}`, AMPL_DECIMALS);
13+
ethers.utils.parseUnits(
14+
`${ample.toFixed ? ample.toFixed(AMPL_DECIMALS) : ample}`,
15+
AMPL_DECIMALS,
16+
);
1117

1218
const INITIAL_SUPPLY = ethers.utils.parseUnits('50', 6 + AMPL_DECIMALS);
1319
const AMPL_ORACLE_DECIMALS = 18;

tasks/deploy/ampleforth.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ txTask('testnet:deploy:ampleforth', 'Deploy ampleforth contract suite')
9090
.addParam('amount', 'Amount of ampl to transfer', 0, types.float)
9191
.setAction(async (args, hre) => {
9292
const txParams = { gasPrice: args.gasPrice, gasLimit: args.gasLimit };
93-
if(txParams.gasPrice == 0){
93+
if (txParams.gasPrice == 0) {
9494
txParams.gasPrice = await hre.ethers.provider.getGasPrice();
9595
}
9696

@@ -153,7 +153,7 @@ txTask('deploy:ampleforth_xc', 'Deploy cross chain ampleforth contract suite')
153153
.addParam('tokenName', 'The symbol of the cross-chain ample ERC-20 token')
154154
.setAction(async (args, hre) => {
155155
const txParams = { gasPrice: args.gasPrice, gasLimit: args.gasLimit };
156-
if(txParams.gasPrice == 0){
156+
if (txParams.gasPrice == 0) {
157157
txParams.gasPrice = await hre.ethers.provider.getGasPrice();
158158
}
159159

tasks/deploy/chain_bridge.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ cbDeployTask(
5959
.addParam('useDeployed', 'Use deployed bridge', false, types.boolean)
6060
.setAction(async (args, hre) => {
6161
const txParams = { gasPrice: args.gasPrice, gasLimit: args.gasLimit };
62-
if(txParams.gasPrice == 0){
62+
if (txParams.gasPrice == 0) {
6363
txParams.gasPrice = await hre.ethers.provider.getGasPrice();
6464
}
6565
const deployer = loadSignerSync(args, hre.ethers.provider);
@@ -206,7 +206,7 @@ cbDeployTask(
206206
.addParam('useDeployed', 'Use deployed bridge', false, types.boolean)
207207
.setAction(async (args, hre) => {
208208
const txParams = { gasPrice: args.gasPrice, gasLimit: args.gasLimit };
209-
if(txParams.gasPrice == 0){
209+
if (txParams.gasPrice == 0) {
210210
txParams.gasPrice = await hre.ethers.provider.getGasPrice();
211211
}
212212
const deployer = loadSignerSync(args, hre.ethers.provider);

0 commit comments

Comments
 (0)