-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
708 additions
and
439 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import type { NetworkType } from "@gearbox-protocol/sdk-gov"; | ||
import { createPublicClient, http } from "viem"; | ||
|
||
import { createClassFromType, detectNetwork } from "../utils/index.js"; | ||
import { envConfig } from "./env.js"; | ||
import { ConfigSchema } from "./schema.js"; | ||
|
||
interface DynamicConfig { | ||
readonly network: NetworkType; | ||
readonly chainId: number; | ||
readonly startBlock: bigint; | ||
} | ||
|
||
const ConfigClass = createClassFromType<ConfigSchema & DynamicConfig>(); | ||
|
||
export class Config extends ConfigClass { | ||
static async load(): Promise<Config> { | ||
const schema = ConfigSchema.parse(envConfig); | ||
|
||
const client = createPublicClient({ | ||
transport: http(schema.ethProviderRpcs[0]), | ||
name: "detect network client", | ||
}); | ||
|
||
const [startBlock, chainId, network] = await Promise.all([ | ||
client.getBlockNumber(), | ||
client.getChainId(), | ||
detectNetwork(client), | ||
]); | ||
return new Config({ | ||
...schema, | ||
startBlock, | ||
chainId: Number(chainId), | ||
network, | ||
}); | ||
} | ||
|
||
public get isPartial(): boolean { | ||
return !!( | ||
this.aavePartialLiquidatorAddress || | ||
this.ghoPartialLiquidatorAddress || | ||
this.deployAaveLiquidatorContracts || | ||
this.deployGhoLiquidatorContracts | ||
); | ||
} | ||
|
||
public get isBatch(): boolean { | ||
return !!( | ||
this.deployBatchLiquidatorContracts || this.batchLiquidatorAddress | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,29 +1 @@ | ||
import { createPublicClient, http } from "viem"; | ||
|
||
import { detectNetwork } from "../utils/index.js"; | ||
import { envConfig } from "./env.js"; | ||
import type { Config } from "./schema.js"; | ||
import { ConfigSchema } from "./schema.js"; | ||
|
||
export async function loadConfig(): Promise<Config> { | ||
const schema = ConfigSchema.parse(envConfig); | ||
|
||
const client = createPublicClient({ | ||
transport: http(schema.ethProviderRpcs[0]), | ||
name: "detect network client", | ||
}); | ||
|
||
const [startBlock, chainId, network] = await Promise.all([ | ||
client.getBlockNumber(), | ||
client.getChainId(), | ||
detectNetwork(client), | ||
]); | ||
return { | ||
...schema, | ||
startBlock, | ||
chainId: Number(chainId), | ||
network, | ||
}; | ||
} | ||
|
||
export type { Config } from "./schema.js"; | ||
export { Config } from "./config.js"; |
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,100 @@ | ||
import { | ||
aaveFlTakerAbi, | ||
aaveLiquidatorAbi, | ||
} from "@gearbox-protocol/liquidator-v2-contracts/abi"; | ||
import { | ||
AaveFLTaker_bytecode, | ||
AaveLiquidator_bytecode, | ||
} from "@gearbox-protocol/liquidator-v2-contracts/bytecode"; | ||
import { contractsByNetwork } from "@gearbox-protocol/sdk-gov"; | ||
import type { Address } from "viem"; | ||
|
||
import type { ILogger } from "../../log/index.js"; | ||
import { Logger } from "../../log/index.js"; | ||
import PartialLiquidatorContract from "./PartialLiquidatorContract.js"; | ||
|
||
export default class AAVELiquidatorContract extends PartialLiquidatorContract { | ||
@Logger("AAVEPartialLiquidator") | ||
logger!: ILogger; | ||
|
||
constructor(router: Address, bot: Address) { | ||
super("AAVE Partial Liquidator", router, bot); | ||
} | ||
|
||
public async deploy(): Promise<void> { | ||
let address = this.config.aavePartialLiquidatorAddress; | ||
const aavePool = | ||
contractsByNetwork[this.config.network].AAVE_V3_LENDING_POOL; | ||
if (!address) { | ||
this.logger.debug( | ||
{ aavePool, router: this.router, bot: this.bot }, | ||
"deploying partial liquidator", | ||
); | ||
|
||
let hash = await this.client.wallet.deployContract({ | ||
abi: aaveFlTakerAbi, | ||
bytecode: AaveFLTaker_bytecode, | ||
args: [aavePool], | ||
}); | ||
this.logger.debug(`waiting for AaveFLTaker to deploy, tx hash: ${hash}`); | ||
const { contractAddress: aaveFlTakerAddr } = | ||
await this.client.pub.waitForTransactionReceipt({ | ||
hash, | ||
timeout: 120_000, | ||
}); | ||
if (!aaveFlTakerAddr) { | ||
throw new Error(`AaveFLTaker was not deployed, tx hash: ${hash}`); | ||
} | ||
let owner = await this.client.pub.readContract({ | ||
abi: aaveFlTakerAbi, | ||
functionName: "owner", | ||
address: aaveFlTakerAddr, | ||
}); | ||
this.logger.debug( | ||
`deployed AaveFLTaker at ${aaveFlTakerAddr} owned by ${owner} in tx ${hash}`, | ||
); | ||
|
||
hash = await this.client.wallet.deployContract({ | ||
abi: aaveLiquidatorAbi, | ||
bytecode: AaveLiquidator_bytecode, | ||
args: [this.router, this.bot, aavePool, aaveFlTakerAddr], | ||
}); | ||
this.logger.debug(`waiting for liquidator to deploy, tx hash: ${hash}`); | ||
const { contractAddress: liquidatorAddr } = | ||
await this.client.pub.waitForTransactionReceipt({ | ||
hash, | ||
timeout: 120_000, | ||
}); | ||
if (!liquidatorAddr) { | ||
throw new Error(`liquidator was not deployed, tx hash: ${hash}`); | ||
} | ||
owner = await this.client.pub.readContract({ | ||
abi: aaveLiquidatorAbi, | ||
address: liquidatorAddr, | ||
functionName: "owner", | ||
}); | ||
this.logger.debug( | ||
`deployed Liquidator at ${liquidatorAddr} owned by ${owner} in tx ${hash}`, | ||
); | ||
|
||
const receipt = await this.client.simulateAndWrite({ | ||
address: aaveFlTakerAddr, | ||
abi: aaveFlTakerAbi, | ||
functionName: "setAllowedFLReceiver", | ||
args: [liquidatorAddr, true], | ||
}); | ||
if (receipt.status === "reverted") { | ||
throw new Error( | ||
`AaveFLTaker.setAllowedFLReceiver reverted, tx hash: ${receipt.transactionHash}`, | ||
); | ||
} | ||
this.logger.debug( | ||
`set allowed flashloan receiver on FLTaker ${aaveFlTakerAddr} to ${liquidatorAddr} in tx ${receipt.transactionHash}`, | ||
); | ||
|
||
address = liquidatorAddr; | ||
} | ||
this.logger.info(`partial liquidator contract addesss: ${address}`); | ||
this.address = address; | ||
} | ||
} |
Oops, something went wrong.