Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ node_modules

# Don't track NPM lockfile (we use Yarn)
package-lock.json

# secrets
packages/liquidator/secret.json
secret.json
42 changes: 41 additions & 1 deletion packages/contracts/test/B.Protocol/FlashArbTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ contract('BAMM', async accounts => {
})


it.only("Arb iotex", async () => {
it("Arb iotex", async () => {
const router = "0x95cB18889B968AbABb9104f30aF5b310bD007Fd8"
const wmatic = "0xA00744882684C3e4747faEFD68D283eA44099D03"
const hmatic = "0x243E33aa7f6787154a8E59d3C27a66db3F8818ee"
Expand Down Expand Up @@ -116,6 +116,46 @@ contract('BAMM', async accounts => {
console.log("done")
*/

})

it.only("Arb fantom", async () => {
const router = "0xF491e7B69E4244ad4002BC14e878a34207E38c29"
const wFTM = "0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83"
const hFTM = "0xfCD8570AD81e6c77b8D252bEbEBA62ed980BD64D"

const iotexBamms = ["0xD3f08B1c4861dacC3ce539B9F4748AA25dCb72aE","0x3A87b540F7EaeC7b20902039818B5Ea78F984305", "0x1346e106b4E2558DAACd2E8207505ce7E31e05CA", "0x01ba129F27df71ADfeDdf2447eFD8698B718D593"]
const keepers = []

for(const bamm of iotexBamms) {
console.log("deploying keepers")
const keeper = await Keeper.new(router, wFTM, hFTM, false)
console.log(keeper.address)
keepers.push(keeper)

console.log("adding 1 bamm")
await keeper.addBamm(bamm)

console.log("setting min profit to 100000000")
await keeper.setMinProfitInUSD("1000000000000000")

console.log("set max attempts to 3")
await keeper.setMaxQtyAttempts(2)

console.log("trying to find smallest qty")
const res = await keeper.findSmallestQty.call({gas: 100000000})
console.log({res})
}

console.log({keepers})
/*
console.log("calling upkeep")
const resUp = await keeper.checkUpkeep.call("0x",{gas: 100000000})
console.log({resUp})
console.log("calling perform")
await keeper.performUpkeep(resUp.performData)
console.log("done")
*/

})

it("Arb", async () => {
Expand Down
26 changes: 15 additions & 11 deletions packages/liquidator/bKeeper.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
const Web3 = require("web3")

const secret = require("./secret.json")
const secret = require(`./${process.env.DAPP_BLOCKCHAIN}/secret.json`)
const abi = require("./abi.json")
const config = require("./config.json")
const config = require(`./${process.env.DAPP_BLOCKCHAIN}/config.json`)

const web3 = new Web3(secret.nodeEndPoint)

// checkUpkeep
const check = async () => {
const check = async (keeperAddress) => {
console.log("checking upkeep...")
const bKeeper = new web3.eth.Contract(abi.bKeeper, config.keeperAddress)
const bKeeper = new web3.eth.Contract(abi.bKeeper, keeperAddress)
const {upkeepNeeded, performData} = await bKeeper.methods.checkUpkeep("0x").call({gas: 100000000})
return {upkeepNeeded, performData}
}

// preform
const preform = async (data) => {
const preform = async (keeperAddress, data) => {
const {privateKey} = secret
const account = web3.eth.accounts.privateKeyToAccount(privateKey)
web3.eth.accounts.wallet.clear()
web3.eth.accounts.wallet.add(account)
console.log("preforming upkeep...")
const bKeeper = new web3.eth.Contract(abi.bKeeper, config.keeperAddress)
const bKeeper = new web3.eth.Contract(abi.bKeeper, keeperAddress)
const gasPrice = await web3.eth.getGasPrice()
await bKeeper.methods.performUpkeep(data).send({from: account.address, gas:3120853, gasPrice})
}

const run = async () => {
const {upkeepNeeded, performData} = await check()
console.log(`upkeep ${upkeepNeeded? "is" : "not"} needed`)
if(upkeepNeeded){
await preform(performData)
for (keeperAddress of config.keeperAddress){
console.log("keeperAddress: " + keeperAddress)
const {upkeepNeeded, performData} = await check(keeperAddress)
console.log(`upkeep ${upkeepNeeded? "is" : "not"} needed`)
if(upkeepNeeded){
await preform(keeperAddress ,performData)
console.log("upkeep preformd!")
process.exit(0)
}
}
console.log("all done!")
}

module.exports = {
Expand Down
35 changes: 3 additions & 32 deletions packages/liquidator/handler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';
const {runOnLambda} = require('./liquidator')
const {runOnLambda: runOnLambdaPolygon} = require('./liquidator_generic')
const {runOnLambda} = require('./liquidator_generic')
const {runBKeeper} = require('./bKeeper')

console.log('process.env.DAPP_BLOCKCHAIN: ' + process.env.DAPP_BLOCKCHAIN)

module.exports.liquidate = async (event) => {
try{
await runOnLambda()
Expand Down Expand Up @@ -33,36 +34,6 @@ module.exports.liquidate = async (event) => {
}
};

module.exports.liquidate_polygon = async (event) => {
try{
await runOnLambdaPolygon()
return {
statusCode: 200,
body: JSON.stringify(
{
message: 'liquidator runOnLambdaPolygon executed successfully!',
input: event,
},
null,
2
),
};
} catch (err){
console.error(err)
return {
statusCode: 500,
body: JSON.stringify(
{
message: err.message,
input: event,
},
null,
2
),
};
}
};

module.exports.bKeeper = async (event) => {
try{
await runBKeeper()
Expand Down
18 changes: 18 additions & 0 deletions packages/liquidator/hundred-fantom/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"fileName": "liquidatorStoredData_hundred_fantom.json",
"comptrollerAddress" : "0x0F390559F258eB8591C8e31Cf0905E97cf36ACE2",
"helperAddress" : "0xd134A5cE381d7db33596D83de74CBBfC34fbc7dC",
"startBlock" : 20683829,
"bammAddresses" : [
"0xD3f08B1c4861dacC3ce539B9F4748AA25dCb72aE",
"0x3A87b540F7EaeC7b20902039818B5Ea78F984305",
"0x1346e106b4E2558DAACd2E8207505ce7E31e05CA",
"0x01ba129F27df71ADfeDdf2447eFD8698B718D593"
],
"keeperAddress" : [
"0x819dC0F46073a4948b7bfaCcCB0951e04B4715Ad",
"0xeF4BdC530196E5b4aFB414Bc12333518C32e7D5A",
"0x17a72E93F2a99CC33AF1746D20FCc9AB50E0f47C",
"0xdccdF48ca09426f5AF8b9b86fC94c59E65Be8639"
]
}
18 changes: 18 additions & 0 deletions packages/liquidator/hundred-iotex/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"fileName": "liquidatorStoredData_hundred_iotex.json",
"comptrollerAddress" : "0x8c6139ff1e9d7c1e32bdafd79948d0895ba0a831",
"helperAddress" : "0x355d1146e172f717daDC86ff5ad47A11eEbdcf48",
"startBlock" : 14580532,
"bammAddresses" : [
"0xCE0A876996248421606F4ad8a09B1D3E15f69EfB",
"0x4Db1d29eA5b51dDADcc5Ab26709dDA49e7eB1E71",
"0x8cF0B1c886Ee522427ef57F5601689352F8161eb",
"0x7D30d048F8693aF30A10aa5D6d281A7A7E6E1245"
],
"keeperAddress" : [
"0x0F0dD66D2d6c1f3b140037018958164c6AB80d56",
"0xe749E89969b897C41c61662b930cf0B8F426B622",
"0x1EcF1b0DE9b4c2D01554062eA2faB84b1917B41d",
"0x998Bf304Ce9Cb215F484aA39d1177b8210078f49"
]
}
4 changes: 2 additions & 2 deletions packages/liquidator/liquidator_generic.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const Web3 = require("web3")
const axios = require("axios")

const secret = require("./secret.json")
const configJson = require("./config.json")
const secret = require(`./${process.env.DAPP_BLOCKCHAIN}/secret.json`)
const configJson = require(`./${process.env.DAPP_BLOCKCHAIN}/config.json`)
const abi = require("./abi.json")
const web3 = new Web3(secret.nodeEndPoint)
const {uploadJsonFile} = require("./s3-client")
Expand Down
6 changes: 4 additions & 2 deletions packages/liquidator/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
service: hundred-polygon
service: hundred-fantom

frameworkVersion: '2 || 3'

Expand All @@ -8,6 +8,8 @@ provider:
runtime: nodejs12.x
profile: bp-sls
lambdaHashingVersion: 20201221
environment:
DAPP_BLOCKCHAIN: ${self:service}
iam:
role:
statements: # permissions for all of your functions can be set here
Expand All @@ -18,7 +20,7 @@ provider:

functions:
liquidate:
handler: handler.liquidate_polygon
handler: handler.liquidate
timeout: 900 # optional, in seconds, default is 6 max is 15minutes
events:
- schedule: rate(10 minutes)
Expand Down