-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathliquidateAccount.js
More file actions
59 lines (48 loc) · 2.02 KB
/
liquidateAccount.js
File metadata and controls
59 lines (48 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const { Perpetual__factory } = require("@firefly-exchange/library/dist/src/contracts/exchange");
const { ethers, toBigNumberStr, Trader } = require("@firefly-exchange/library");
const environment = require("./environments.json");
require('dotenv').config();
envName = process.env.env;
env = environment[envName]
market = process.env.market;
console.log("Env:", envName);
console.log("Market:", market);
const providerURL = env["URL"];
const liquidationContractAddress = env[market]["IsolatedLiquidation"]
const perpetualContractAddress = env[market]["Perpetual"]
const provider = new ethers.providers.JsonRpcProvider(providerURL);
async function main(liquidatorAddress, liquidatorPvtKey, leverage, quantity, positionSide){
const liquidatorWallet = new ethers.Wallet(liquidatorPvtKey, provider);
const contract = Perpetual__factory.connect(perpetualContractAddress, liquidatorWallet);
const params = await Trader.setupLiquidationTrade(
{
// complete order quantity
quantity: toBigNumberStr(quantity),
// is buy should always be same as maker order is buy.
isBuy: positionSide == "long",
// use default leverage as one
leverage: toBigNumberStr(leverage),
allOrNothing: false
},
liquidatorWallet.address,
liquidatorAddress,
liquidationContractAddress
);
await ( await contract
.connect(liquidatorWallet)
.trade(
params.accounts,
[params.data]
)
).wait()
}
if(require.main === module){
if(process.argv.length != 7){
console.error(`Provide account address to be liquidated, liquidator's private key, leverage and quantity
\ne.g. "yarn liquidate <liquidate address> <liquidator pvt key> <leverage> <quantity> <position side>"
\ne.g "yarn liquidate address key2 4 10 long
`);
process.exit(1);
};
main(process.argv[2], process.argv[3], process.argv[4], process.argv[5], process.argv[6]);
}