Scenarios

In scenarios, the context for the simulation is set, such as providing tokens/coins to addresses used in the simulation, calling necessary functions, and creating contract instances.

Built-in Functions:

  • provider (json rpc provider)

  • localhost (fork port url)

  • ethers (ethers.js library)

  • log (to log during the simulation for debugging)

  • deployedContracts (contracts deployed from the contract execution)

These functions can be used inside all scripts without importing as they are provided by the backend.

Accessing Deployed Contracts:

The deployed contracts can be accessed using the deployedContracts variable, which is populated by the backend.

let oracleContract = deployedContracts.Main;

The contract can be accessed by its name.

Returning Contracts and Variables:

It is essential to return all contract instances and variables from the scenario. Contracts are used to verify methods and decode events in the block explorer, whereas variables can be reused in later scenarios, observers, and assertions.

let newContract = new ethers.Contract(abi, address, provider);
let admin =0x00123’;
return { newContract, admin };

Accessing Variables and Contracts in Other Scripts:

To access variables or contracts returned by the scenario, use the scenarioRet variable.

let newContract = scenarioRet.newContract;
let admin = scenarioRet.admin;

This method works the same for all other variables as well. By following these guidelines, you can ensure that your scenarios are properly set up and that your scripts interact correctly with the ChainRisk simulator. In the compound black thursday scenario, we are initially defining the variables, making contract instances, providing funds to the wallet used, calling functions to upgrade dummy oracle for price manipulation and at last we are returning all the variables and contracts.

Last updated