-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from VenusProtocol/refactor-create-base-class
Refactor create base class
- Loading branch information
Showing
27 changed files
with
299 additions
and
353 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
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,47 @@ | ||
import getConfig from "./config"; | ||
import type { SUPPORTED_CHAINS } from "./config/chains"; | ||
import publicClient from "./config/clients/publicClient"; | ||
import walletClient from "./config/clients/walletClient"; | ||
import { ConverterBotMessage } from "./converter-bot/types"; | ||
import { SwapProvider } from "./providers"; | ||
|
||
const config = getConfig(); | ||
|
||
class BotBase { | ||
protected chainName: SUPPORTED_CHAINS; | ||
protected subscriber: undefined | ((msg: ConverterBotMessage) => void); | ||
protected simulate: boolean; | ||
protected swapProvider: SwapProvider; | ||
public publicClient: typeof publicClient; | ||
public walletClient: typeof walletClient; | ||
|
||
constructor({ | ||
subscriber, | ||
swapProvider, | ||
simulate, | ||
}: { | ||
subscriber?: (msg: ConverterBotMessage) => void; | ||
swapProvider: typeof SwapProvider; | ||
simulate: boolean; | ||
}) { | ||
this.subscriber = subscriber; | ||
this.swapProvider = new swapProvider({ subscriber }); | ||
this.publicClient = publicClient; | ||
this.walletClient = walletClient; | ||
this.simulate = simulate; | ||
this.chainName = config.network.name; | ||
} | ||
protected sendMessage({ | ||
type, | ||
trx = undefined, | ||
error = undefined, | ||
context = undefined, | ||
blockNumber = undefined, | ||
}: Partial<ConverterBotMessage>) { | ||
if (this.subscriber) { | ||
this.subscriber({ type, trx, error, context, blockNumber } as ConverterBotMessage); | ||
} | ||
} | ||
} | ||
|
||
export default BotBase; |
6 changes: 3 additions & 3 deletions
6
packages/keeper-bots/src/config/clients/__mocks__/publicClient.ts
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,11 +1,11 @@ | ||
const getPublicClientMock = () => ({ | ||
const publicClientMock = { | ||
simulateContract: jest.fn(), | ||
readContract: jest.fn(), | ||
multicall: jest.fn(), | ||
getBlock: jest.fn(), | ||
getBlockNumber: jest.fn(), | ||
waitForTransactionReceipt: jest.fn(), | ||
estimateContractGas: jest.fn(), | ||
}); | ||
}; | ||
|
||
export default getPublicClientMock; | ||
export default publicClientMock; |
6 changes: 3 additions & 3 deletions
6
packages/keeper-bots/src/config/clients/__mocks__/walletClient.ts
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,8 +1,8 @@ | ||
const getWalletClientMock = () => ({ | ||
const walletClientMock = { | ||
account: { | ||
address: "0x4CCeBa2d7D2B4fdcE4304d3e09a1fea9fbEb1528", | ||
}, | ||
writeContract: jest.fn(() => "0xtransactionHash"), | ||
}); | ||
}; | ||
|
||
export default getWalletClientMock; | ||
export default walletClientMock; |
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 |
---|---|---|
|
@@ -12,4 +12,4 @@ const getPublicClient = () => { | |
}); | ||
}; | ||
|
||
export default getPublicClient; | ||
export default getPublicClient(); |
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 |
---|---|---|
|
@@ -22,4 +22,4 @@ const getWalletClient = () => { | |
}); | ||
}; | ||
|
||
export default getWalletClient; | ||
export default getWalletClient(); |
Oops, something went wrong.