Skip to content
Merged
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
26 changes: 19 additions & 7 deletions hardhat/tasks/task-interact.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ task('interact', 'Interact with a deployed Synthetix instance from the command l
.addOptionalParam('privateKey', 'Private key to use to sign txs')
.addOptionalParam('providerUrl', 'The http provider to use for communicating with the blockchain')
.addOptionalParam('deploymentPath', 'Specify the path to the deployment data directory')
.addOptionalParam('blockTag', 'Specify the block tag to interact at, per ethers.js specification')
.setAction(async (taskArguments, hre) => {
const { useOvm, useFork, deploymentPath, targetNetwork } = taskArguments;
let { providerUrl, gasLimit, gasPrice, privateKey } = taskArguments;
let { providerUrl, gasLimit, gasPrice, privateKey, blockTag } = taskArguments;
// ------------------
// Default values per network
// ------------------
Expand All @@ -34,6 +35,10 @@ task('interact', 'Interact with a deployed Synthetix instance from the command l
gasPrice = synthetix.constants.OVM_GAS_PRICE_GWEI;
gasLimit = undefined;
}
blockTag = blockTag || 'latest';
if (!isNaN(blockTag)) {
blockTag = parseInt(blockTag);
}

// ------------------
// Setup
Expand Down Expand Up @@ -111,6 +116,7 @@ task('interact', 'Interact with a deployed Synthetix instance from the command l
gasPrice,
deploymentFilePath,
wallet,
blockTag,
});

async function pickContract() {
Expand Down Expand Up @@ -162,7 +168,7 @@ task('interact', 'Interact with a deployed Synthetix instance from the command l

const contract = new ethers.Contract(target.address, source.abi, wallet || provider);
if (source.bytecode === '') {
const code = await provider.getCode(target.address);
const code = await provider.getCode(target.address, blockTag);
console.log(red(` > No code at ${target.address}, code: ${code}`));
}

Expand Down Expand Up @@ -315,9 +321,12 @@ task('interact', 'Interact with a deployed Synthetix instance from the command l
// READ ONLY
if (abiItem.stateMutability === 'view' || abiItem.stateMutability === 'pure') {
console.log(gray(' > Querying...'));
const overrides = {
blockTag,
};

try {
result = await contract[abiItemName](...inputs);
result = await contract[abiItemName](...inputs, overrides);
} catch (err) {
error = err;
}
Expand Down Expand Up @@ -363,6 +372,7 @@ task('interact', 'Interact with a deployed Synthetix instance from the command l
result = await _confirmTx({
tx: result.tx,
provider,
blockTag,
});

if (result.success) {
Expand Down Expand Up @@ -465,6 +475,7 @@ async function _printHeader({
gasPrice,
deploymentFilePath,
wallet,
blockTag,
}) {
console.clear();
console.log(green(`Interactive Synthetix CLI (v${synthetixPackage.version})`));
Expand All @@ -480,6 +491,7 @@ async function _printHeader({
console.log(gray(`> Network: ${network}`));
console.log(gray(`> Gas price: ${gasPrice}`));
console.log(gray(`> OVM: ${useOvm}`));
console.log(gray(`> Block tag: ${blockTag}`));
console.log(yellow(`> Target deployment: ${path.dirname(deploymentFilePath)}`));

if (wallet) {
Expand Down Expand Up @@ -607,7 +619,7 @@ async function _sendTx({ txPromise }) {
}
}

async function _confirmTx({ tx, provider }) {
async function _confirmTx({ tx, provider, blockTag }) {
try {
const receipt = await tx.wait();

Expand All @@ -617,7 +629,7 @@ async function _confirmTx({ tx, provider }) {
};
} catch (error) {
try {
error.reason = await _getRevertReason({ tx, provider });
error.reason = await _getRevertReason({ tx, provider, blockTag });

return {
success: false,
Expand Down Expand Up @@ -649,8 +661,8 @@ function _hexToString(hex) {
return str.substring(0, str.length - 4);
}

async function _getRevertReason({ tx, provider }) {
const code = (await provider.call(tx)).substr(138);
async function _getRevertReason({ tx, provider, blockTag }) {
const code = (await provider.call(tx, blockTag)).substr(138);
const hex = `0x${code}`;

if (code.length === '64') {
Expand Down