Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add defender utils and use of signer
- Loading branch information
1 parent
d6f92a6
commit 329a48c
Showing
11 changed files
with
89 additions
and
33 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { formatEther } from '@ethersproject/units'; | ||
import { DefenderRelaySigner, DefenderRelayProvider } from 'defender-relay-client/lib/ethers'; | ||
import { Signer } from 'ethers'; | ||
import { HardhatRuntimeEnvironment } from 'hardhat/types'; | ||
import { DRE, impersonateAccountsHardhat } from './misc-utils'; | ||
import { usingTenderly } from './tenderly-utils'; | ||
|
||
export const usingDefender = () => process.env.DEFENDER === 'true'; | ||
|
||
export const getDefenderRelaySigner = async () => { | ||
const { DEFENDER_API_KEY, DEFENDER_SECRET_KEY } = process.env; | ||
let defenderSigner: Signer; | ||
|
||
if (!DEFENDER_API_KEY || !DEFENDER_SECRET_KEY) { | ||
throw new Error('Defender secrets required'); | ||
} | ||
|
||
const credentials = { apiKey: DEFENDER_API_KEY, apiSecret: DEFENDER_SECRET_KEY }; | ||
|
||
defenderSigner = new DefenderRelaySigner(credentials, new DefenderRelayProvider(credentials), { | ||
speed: 'fast', | ||
}); | ||
|
||
const defenderAddress = await defenderSigner.getAddress(); | ||
console.log(' - Using Defender Relay: ', defenderAddress); | ||
|
||
// Reemplace signer if FORK=main is active | ||
if (process.env.FORK === 'main') { | ||
console.log(' - Impersonating Defender Relay'); | ||
await impersonateAccountsHardhat([defenderAddress]); | ||
defenderSigner = await (DRE as HardhatRuntimeEnvironment).ethers.getSigner(defenderAddress); | ||
} | ||
// Reemplace signer if Tenderly network is active | ||
if (usingTenderly()) { | ||
console.log(' - Impersonating Defender Relay via Tenderly'); | ||
defenderSigner = await (DRE as HardhatRuntimeEnvironment).ethers.getSigner(defenderAddress); | ||
} | ||
console.log(' - Balance: ', formatEther(await defenderSigner.getBalance())); | ||
|
||
return defenderSigner; | ||
}; |
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
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