forked from sphinx-labs/sphinx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ex): make executor most robust to errors and cancelled bundles
- Loading branch information
1 parent
4d7ac72
commit fb1168f
Showing
9 changed files
with
246 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@chugsplash/core': patch | ||
'@chugsplash/executor': patch | ||
'@chugsplash/plugins': patch | ||
--- | ||
|
||
Make executor most robust to errors and cancelled bundles. Ensure that executor receives payment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { ChugSplashManagerABI } from '@chugsplash/contracts' | ||
import { ethers } from 'ethers' | ||
|
||
import { getChugSplashManagerProxyAddress } from './utils' | ||
import { ChugSplashConfig } from './config/types' | ||
|
||
/** | ||
* Gets the amount ETH in the ChugSplashManager that can be used to execute a deployment. | ||
* This equals the ChugSplashManager's balance minus the total debt owed to executors. | ||
*/ | ||
export const getOwnerBalanceInChugSplashManager = async ( | ||
provider: ethers.providers.JsonRpcProvider, | ||
projectName: string | ||
): Promise<ethers.BigNumber> => { | ||
const ChugSplashManager = new ethers.Contract( | ||
getChugSplashManagerProxyAddress(projectName), | ||
ChugSplashManagerABI, | ||
provider | ||
) | ||
|
||
const managerBalance = await provider.getBalance(ChugSplashManager.address) | ||
const totalDebt = await ChugSplashManager.totalDebt() | ||
return managerBalance.sub(totalDebt) | ||
} | ||
|
||
/** | ||
* Gets the minimum amount that must be sent to the ChugSplashManager in order to execute the | ||
* ChugSplash config. If this function returns zero, then there is already a sufficient amount of | ||
* funds. | ||
* | ||
* @param provider JSON RPC provider. | ||
* @param parsedConfig Parsed ChugSplash config. | ||
* @returns The minimum amount to send to the ChugSplashManager in order to execute the config | ||
* (denominated in wei). | ||
*/ | ||
export const getExecutionAmountToSend = async ( | ||
provider: ethers.providers.JsonRpcProvider, | ||
parsedConfig: ChugSplashConfig | ||
): Promise<ethers.BigNumber> => { | ||
const totalExecutionAmount = await simulateExecution(provider, parsedConfig) | ||
const availableExecutionAmount = await getOwnerBalanceInChugSplashManager( | ||
provider, | ||
parsedConfig.options.projectName | ||
) | ||
const executionAmount = totalExecutionAmount.sub(availableExecutionAmount) | ||
return executionAmount.gt(0) ? executionAmount : ethers.BigNumber.from(0) | ||
} | ||
|
||
export const simulateExecution = async ( | ||
provider: ethers.providers.JsonRpcProvider, | ||
parsedConfig: ChugSplashConfig | ||
) => { | ||
provider | ||
parsedConfig | ||
|
||
// TODO | ||
return ethers.utils.parseEther('0.25') | ||
} | ||
|
||
/** | ||
* Returns the amount to send to the ChugSplashManager to execute a bundle, plus a buffer in case | ||
* the gas price increases during execution. If this returns zero, there is already a sufficient | ||
* amount of funds in the ChugSplashManager. | ||
* | ||
* @param provider JSON RPC provider. | ||
* @param parsedConfig Parsed ChugSplash config. | ||
* @returns The amount required to fund a bundle, plus a buffer. Denominated in wei. | ||
*/ | ||
export const getExecutionAmountToSendPlusBuffer = async ( | ||
provider: ethers.providers.JsonRpcProvider, | ||
parsedConfig: ChugSplashConfig | ||
) => { | ||
const executionAmount = await getExecutionAmountToSend(provider, parsedConfig) | ||
return executionAmount.mul(15).div(10) | ||
} | ||
|
||
export const hasSufficientFundsForExecution = async ( | ||
provider: ethers.providers.JsonRpcProvider, | ||
parsedConfig: ChugSplashConfig | ||
): Promise<boolean> => { | ||
// Get the amount of funds that must be sent to the ChugSplashManager in order to execute the | ||
// bundle. | ||
const executionAmount = await getExecutionAmountToSend(provider, parsedConfig) | ||
return executionAmount.eq(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.