torch-liquidation-bot 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -7
- package/readme.md +46 -80
- package/dist/config.d.ts +0 -6
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -51
- package/dist/config.js.map +0 -1
- package/dist/index.d.ts +0 -28
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -172
- package/dist/index.js.map +0 -1
- package/dist/liquidator.d.ts +0 -17
- package/dist/liquidator.d.ts.map +0 -1
- package/dist/liquidator.js +0 -72
- package/dist/liquidator.js.map +0 -1
- package/dist/logger.d.ts +0 -17
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -54
- package/dist/logger.js.map +0 -1
- package/dist/monitor.d.ts +0 -27
- package/dist/monitor.d.ts.map +0 -1
- package/dist/monitor.js +0 -136
- package/dist/monitor.js.map +0 -1
- package/dist/risk-scorer.d.ts +0 -13
- package/dist/risk-scorer.d.ts.map +0 -1
- package/dist/risk-scorer.js +0 -102
- package/dist/risk-scorer.js.map +0 -1
- package/dist/scanner.d.ts +0 -11
- package/dist/scanner.d.ts.map +0 -1
- package/dist/scanner.js +0 -55
- package/dist/scanner.js.map +0 -1
- package/dist/types.d.ts +0 -69
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -8
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -9
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -24
- package/dist/utils.js.map +0 -1
- package/dist/wallet-profiler.d.ts +0 -21
- package/dist/wallet-profiler.d.ts.map +0 -1
- package/dist/wallet-profiler.js +0 -116
- package/dist/wallet-profiler.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "torch-liquidation-bot",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "lending
|
|
3
|
+
"version": "2.0.2",
|
|
4
|
+
"description": "read-only lending market scanner for Torch Market on Solana",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"bin": {
|
|
@@ -14,15 +14,10 @@
|
|
|
14
14
|
"build": "tsc",
|
|
15
15
|
"clean": "rm -rf dist",
|
|
16
16
|
"test": "npx tsx tests/test_readonly.ts",
|
|
17
|
-
"test:lending": "npx tsx tests/test_lending.ts",
|
|
18
|
-
"test:bot": "npx tsx tests/test_bot.ts",
|
|
19
17
|
"format": "prettier --write src/ tests/"
|
|
20
18
|
},
|
|
21
19
|
"dependencies": {
|
|
22
|
-
"@coral-xyz/anchor": "^0.32.1",
|
|
23
|
-
"@solana/spl-token": "^0.4.14",
|
|
24
20
|
"@solana/web3.js": "^1.98.4",
|
|
25
|
-
"bs58": "^6.0.0",
|
|
26
21
|
"torchsdk": "^1.0.5"
|
|
27
22
|
},
|
|
28
23
|
"devDependencies": {
|
|
@@ -32,6 +27,10 @@
|
|
|
32
27
|
},
|
|
33
28
|
"peerDependencies": {
|
|
34
29
|
"@solana/web3.js": "^1.98.0"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "torch-liquidation-bot-ro"
|
|
35
34
|
},
|
|
36
35
|
"license": "MIT",
|
|
37
36
|
"packageManager": "pnpm@9.10.0+sha512.73a29afa36a0d092ece5271de5177ecbf8318d454ecd701343131b8ebc0c1a91c487da46ab77c8e596d6acf1461e3594ced4becedf8921b074fbd8653ed7051c"
|
package/readme.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
# torch-liquidation-bot
|
|
1
|
+
# torch-liquidation-bot v2.0.1 (Read-Only)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Read-only lending market scanner for [Torch Market](https://torch.market) on Solana. No wallet required. Only an RPC endpoint is needed.
|
|
4
|
+
|
|
5
|
+
> **v2.0.0 Breaking Change:** All wallet-dependent code (bot mode, watch mode, transaction signing) was removed. The source tree contains only read-only code. No wallet, no keypair, no signing.
|
|
4
6
|
|
|
5
7
|
## Install
|
|
6
8
|
|
|
@@ -8,96 +10,62 @@ Multi-token liquidation bot for [Torch Market](https://torch.market) lending on
|
|
|
8
10
|
npm install torch-liquidation-bot
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
## How It Works
|
|
12
|
-
|
|
13
|
-
Every migrated token on Torch has a built-in lending market. Holders borrow SOL against their tokens. When a borrower's loan-to-value ratio exceeds 65%, anyone can liquidate the position and collect a 10% bonus on the collateral.
|
|
14
|
-
|
|
15
|
-
This bot finds those opportunities before other bots do by **predicting** which positions will go underwater:
|
|
16
|
-
|
|
17
|
-
1. **Scan** -- discovers all tokens with active lending markets
|
|
18
|
-
2. **Profile** -- checks each borrower's SAID reputation and trade history
|
|
19
|
-
3. **Score** -- rates every loan on a 4-factor risk model (0-100)
|
|
20
|
-
4. **Liquidate** -- executes when a position crosses the threshold and the profit exceeds your minimum
|
|
21
|
-
|
|
22
13
|
## Quick Start
|
|
23
14
|
|
|
24
15
|
```bash
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
## Modes
|
|
16
|
+
# show lending info for all migrated tokens
|
|
17
|
+
RPC_URL=<rpc> npx torch-liquidation-bot
|
|
29
18
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
Runs two concurrent loops:
|
|
33
|
-
- **Scan loop** (every 60s) -- finds tokens with active lending, snapshots prices
|
|
34
|
-
- **Score loop** (every 15s) -- profiles borrowers, scores loans, executes liquidations
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
MODE=bot WALLET=<key> RPC_URL=<rpc> npx torch-liquidation-bot
|
|
19
|
+
# show lending info for a specific token
|
|
20
|
+
MINT=<mint> RPC_URL=<rpc> npx torch-liquidation-bot
|
|
38
21
|
```
|
|
39
22
|
|
|
40
|
-
|
|
23
|
+
## What It Does
|
|
41
24
|
|
|
42
|
-
|
|
43
|
-
# all migrated tokens with lending
|
|
44
|
-
MODE=info RPC_URL=<rpc> npx torch-liquidation-bot
|
|
45
|
-
|
|
46
|
-
# specific token
|
|
47
|
-
MODE=info MINT=<mint> RPC_URL=<rpc> npx torch-liquidation-bot
|
|
48
|
-
```
|
|
25
|
+
Every migrated token on Torch has a built-in lending market. This skill discovers those markets and displays their parameters — interest rates, LTV thresholds, treasury balances, and active loan counts.
|
|
49
26
|
|
|
50
|
-
|
|
27
|
+
That's it. No wallet loaded. No transactions built. No state changes.
|
|
51
28
|
|
|
52
|
-
|
|
53
|
-
MODE=watch MINT=<mint> WALLET=<key> RPC_URL=<rpc> npx torch-liquidation-bot
|
|
29
|
+
## Configuration
|
|
54
30
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
31
|
+
| Variable | Required | Default | Description |
|
|
32
|
+
|----------|----------|---------|-------------|
|
|
33
|
+
| `RPC_URL` | yes | -- | Solana RPC endpoint |
|
|
34
|
+
| `MINT` | no | -- | Token mint address (omit to show all tokens) |
|
|
35
|
+
| `LOG_LEVEL` | no | `info` | `debug`, `info`, `warn`, `error` |
|
|
58
36
|
|
|
59
|
-
|
|
37
|
+
No `WALLET`, no `MODE`, no bot-specific config.
|
|
60
38
|
|
|
61
|
-
|
|
39
|
+
## Programmatic Usage
|
|
62
40
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
| Wallet risk | 20% | SAID trust tier + trade win/loss ratio |
|
|
68
|
-
| Interest burden | 10% | Accrued interest relative to collateral value |
|
|
41
|
+
```typescript
|
|
42
|
+
import { loadReadOnlyConfig } from 'torch-liquidation-bot/config'
|
|
43
|
+
import { Connection } from '@solana/web3.js'
|
|
44
|
+
import { getTokens, getLendingInfo } from 'torchsdk'
|
|
69
45
|
|
|
70
|
-
|
|
46
|
+
const config = loadReadOnlyConfig()
|
|
47
|
+
const connection = new Connection(config.rpcUrl, 'confirmed')
|
|
71
48
|
|
|
72
|
-
|
|
49
|
+
const { tokens } = await getTokens(connection, {
|
|
50
|
+
status: 'migrated',
|
|
51
|
+
sort: 'volume',
|
|
52
|
+
limit: 50,
|
|
53
|
+
})
|
|
73
54
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
| `MINT` | info/watch | -- | Token mint address |
|
|
80
|
-
| `SCAN_INTERVAL_MS` | no | `60000` | Token discovery interval |
|
|
81
|
-
| `SCORE_INTERVAL_MS` | no | `15000` | Position scoring interval |
|
|
82
|
-
| `MIN_PROFIT_SOL` | no | `0.01` | Minimum profit to execute liquidation |
|
|
83
|
-
| `RISK_THRESHOLD` | no | `60` | Risk score cutoff for close monitoring |
|
|
84
|
-
| `PRICE_HISTORY` | no | `20` | Price snapshots to keep for momentum |
|
|
85
|
-
| `LOG_LEVEL` | no | `info` | `debug`, `info`, `warn`, `error` |
|
|
55
|
+
for (const t of tokens) {
|
|
56
|
+
const lending = await getLendingInfo(connection, t.mint)
|
|
57
|
+
console.log(`${t.symbol}: ${lending.active_loans} active loans`)
|
|
58
|
+
}
|
|
59
|
+
```
|
|
86
60
|
|
|
87
61
|
## Architecture
|
|
88
62
|
|
|
89
63
|
```
|
|
90
64
|
src/
|
|
91
|
-
├── types.ts
|
|
92
|
-
├── config.ts
|
|
93
|
-
├──
|
|
94
|
-
|
|
95
|
-
├── scanner.ts — discovers tokens with active lending
|
|
96
|
-
├── wallet-profiler.ts — SAID reputation + trade history
|
|
97
|
-
├── risk-scorer.ts — 4-factor risk model
|
|
98
|
-
├── liquidator.ts — executes liquidation txs
|
|
99
|
-
├── monitor.ts — scan + score orchestration
|
|
100
|
-
└── index.ts — entry point
|
|
65
|
+
├── types.ts — ReadOnlyConfig interface
|
|
66
|
+
├── config.ts — loadReadOnlyConfig()
|
|
67
|
+
├── utils.ts — sol() + bpsToPercent() helpers
|
|
68
|
+
└── index.ts — read-only entry point
|
|
101
69
|
```
|
|
102
70
|
|
|
103
71
|
## Lending Parameters
|
|
@@ -116,23 +84,21 @@ Requires [Surfpool](https://github.com/nicholasgasior/surfpool) running a mainne
|
|
|
116
84
|
|
|
117
85
|
```bash
|
|
118
86
|
surfpool start --network mainnet --no-tui
|
|
119
|
-
pnpm test
|
|
120
|
-
pnpm test:bot # bot module test (scanner, profiler, scorer, liquidator)
|
|
87
|
+
pnpm test # read-only test
|
|
121
88
|
```
|
|
122
89
|
|
|
123
90
|
## Security
|
|
124
91
|
|
|
125
|
-
-
|
|
126
|
-
-
|
|
127
|
-
-
|
|
128
|
-
-
|
|
129
|
-
-
|
|
92
|
+
- No wallet loaded, no keypair decoded, no private key in memory
|
|
93
|
+
- No transaction building, no signing, no state changes
|
|
94
|
+
- Outbound connections: Solana RPC only
|
|
95
|
+
- Minimal dependencies: `@solana/web3.js` + `torchsdk`
|
|
96
|
+
- No post-install hooks, no remote code fetching
|
|
130
97
|
|
|
131
98
|
## Links
|
|
132
99
|
|
|
133
|
-
- [torchsdk](https://github.com/mrsirg97-rgb/torchsdk) -- the SDK this
|
|
100
|
+
- [torchsdk](https://github.com/mrsirg97-rgb/torchsdk) -- the SDK this skill reads from
|
|
134
101
|
- [Torch Market](https://torch.market) -- the protocol
|
|
135
|
-
- [SAID Protocol](https://saidprotocol.com) -- wallet reputation layer
|
|
136
102
|
- [ClawHub](https://clawhub.ai/mrsirg97-rgb/torchliquidationbot) -- skill registry
|
|
137
103
|
|
|
138
104
|
## License
|
package/dist/config.d.ts
DELETED
package/dist/config.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,SAAS,CAAA;AAIlD,wBAAgB,UAAU,IAAI,SAAS,CAuCtC"}
|
package/dist/config.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* config.ts — loads environment variables into a typed BotConfig.
|
|
4
|
-
*/
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.loadConfig = loadConfig;
|
|
10
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
11
|
-
const bs58_1 = __importDefault(require("bs58"));
|
|
12
|
-
const torchsdk_1 = require("torchsdk");
|
|
13
|
-
const LOG_LEVELS = ['debug', 'info', 'warn', 'error'];
|
|
14
|
-
function loadConfig() {
|
|
15
|
-
const rpcUrl = process.env.RPC_URL;
|
|
16
|
-
if (!rpcUrl)
|
|
17
|
-
throw new Error('RPC_URL env var is required');
|
|
18
|
-
const walletKey = process.env.WALLET;
|
|
19
|
-
if (!walletKey)
|
|
20
|
-
throw new Error('WALLET env var is required (base58 private key)');
|
|
21
|
-
const logLevel = (process.env.LOG_LEVEL ?? 'info');
|
|
22
|
-
if (!LOG_LEVELS.includes(logLevel)) {
|
|
23
|
-
throw new Error(`LOG_LEVEL must be one of: ${LOG_LEVELS.join(', ')}`);
|
|
24
|
-
}
|
|
25
|
-
const minProfitSol = Number(process.env.MIN_PROFIT_SOL ?? '0.01');
|
|
26
|
-
const scanIntervalMs = Number(process.env.SCAN_INTERVAL_MS ?? '60000');
|
|
27
|
-
const scoreIntervalMs = Number(process.env.SCORE_INTERVAL_MS ?? '15000');
|
|
28
|
-
const riskThreshold = Number(process.env.RISK_THRESHOLD ?? '60');
|
|
29
|
-
const priceHistoryDepth = Number(process.env.PRICE_HISTORY ?? '20');
|
|
30
|
-
if (isNaN(scanIntervalMs) || scanIntervalMs < 1000)
|
|
31
|
-
throw new Error('SCAN_INTERVAL_MS must be >= 1000');
|
|
32
|
-
if (isNaN(scoreIntervalMs) || scoreIntervalMs < 1000)
|
|
33
|
-
throw new Error('SCORE_INTERVAL_MS must be >= 1000');
|
|
34
|
-
if (isNaN(riskThreshold) || riskThreshold < 0 || riskThreshold > 100)
|
|
35
|
-
throw new Error('RISK_THRESHOLD must be 0-100');
|
|
36
|
-
if (isNaN(priceHistoryDepth) || priceHistoryDepth < 2)
|
|
37
|
-
throw new Error('PRICE_HISTORY must be >= 2');
|
|
38
|
-
if (isNaN(minProfitSol) || minProfitSol < 0)
|
|
39
|
-
throw new Error('MIN_PROFIT_SOL must be >= 0');
|
|
40
|
-
return {
|
|
41
|
-
rpcUrl,
|
|
42
|
-
walletKeypair: web3_js_1.Keypair.fromSecretKey(bs58_1.default.decode(walletKey)),
|
|
43
|
-
scanIntervalMs,
|
|
44
|
-
scoreIntervalMs,
|
|
45
|
-
minProfitLamports: Math.floor(minProfitSol * torchsdk_1.LAMPORTS_PER_SOL),
|
|
46
|
-
riskThreshold,
|
|
47
|
-
priceHistoryDepth,
|
|
48
|
-
logLevel,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;AASH,gCAuCC;AA9CD,6CAAyC;AACzC,gDAAuB;AACvB,uCAA2C;AAG3C,MAAM,UAAU,GAAe,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;AAEjE,SAAgB,UAAU;IACxB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAA;IAClC,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;IAE3D,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAA;IACpC,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAA;IAElF,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,IAA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AAA;IAEhD,OAAO;QACL,MAAM;QACN,aAAa,EAAE,iBAAO,CAAC,aAAa,CAAC,cAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC5D,cAAc;QACd,eAAe;QACf,iBAAiB,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,2BAAgB,CAAC;QAC9D,aAAa;QACb,iBAAiB;QACjB,QAAQ;KACT,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* torch-lending-monitor
|
|
4
|
-
*
|
|
5
|
-
* multi-token liquidation bot that discovers lending markets, profiles
|
|
6
|
-
* borrower wallets, predicts which loans will fail, and executes
|
|
7
|
-
* profitable liquidations.
|
|
8
|
-
*
|
|
9
|
-
* modes:
|
|
10
|
-
* info — display lending parameters for a token (or all tokens) (default)
|
|
11
|
-
* watch — monitor your own loan health in real-time
|
|
12
|
-
* bot — run the full liquidation bot
|
|
13
|
-
*
|
|
14
|
-
* usage:
|
|
15
|
-
* # show all migrated tokens with lending
|
|
16
|
-
* RPC_URL=<rpc> npx tsx src/index.ts
|
|
17
|
-
*
|
|
18
|
-
* # show lending info for one token
|
|
19
|
-
* MODE=info MINT=<mint> RPC_URL=<rpc> npx tsx src/index.ts
|
|
20
|
-
*
|
|
21
|
-
* # watch your loan health
|
|
22
|
-
* MODE=watch MINT=<mint> WALLET=<key> RPC_URL=<rpc> npx tsx src/index.ts
|
|
23
|
-
*
|
|
24
|
-
* # run the liquidation bot
|
|
25
|
-
* MODE=bot WALLET=<key> RPC_URL=<rpc> npx tsx src/index.ts
|
|
26
|
-
*/
|
|
27
|
-
export {};
|
|
28
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG"}
|
package/dist/index.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
/**
|
|
4
|
-
* torch-lending-monitor
|
|
5
|
-
*
|
|
6
|
-
* multi-token liquidation bot that discovers lending markets, profiles
|
|
7
|
-
* borrower wallets, predicts which loans will fail, and executes
|
|
8
|
-
* profitable liquidations.
|
|
9
|
-
*
|
|
10
|
-
* modes:
|
|
11
|
-
* info — display lending parameters for a token (or all tokens) (default)
|
|
12
|
-
* watch — monitor your own loan health in real-time
|
|
13
|
-
* bot — run the full liquidation bot
|
|
14
|
-
*
|
|
15
|
-
* usage:
|
|
16
|
-
* # show all migrated tokens with lending
|
|
17
|
-
* RPC_URL=<rpc> npx tsx src/index.ts
|
|
18
|
-
*
|
|
19
|
-
* # show lending info for one token
|
|
20
|
-
* MODE=info MINT=<mint> RPC_URL=<rpc> npx tsx src/index.ts
|
|
21
|
-
*
|
|
22
|
-
* # watch your loan health
|
|
23
|
-
* MODE=watch MINT=<mint> WALLET=<key> RPC_URL=<rpc> npx tsx src/index.ts
|
|
24
|
-
*
|
|
25
|
-
* # run the liquidation bot
|
|
26
|
-
* MODE=bot WALLET=<key> RPC_URL=<rpc> npx tsx src/index.ts
|
|
27
|
-
*/
|
|
28
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
-
};
|
|
31
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
33
|
-
const bs58_1 = __importDefault(require("bs58"));
|
|
34
|
-
const torchsdk_1 = require("torchsdk");
|
|
35
|
-
const monitor_1 = require("./monitor");
|
|
36
|
-
const config_1 = require("./config");
|
|
37
|
-
const utils_1 = require("./utils");
|
|
38
|
-
// ---------------------------------------------------------------------------
|
|
39
|
-
// helpers for info/watch modes (don't need full config)
|
|
40
|
-
// ---------------------------------------------------------------------------
|
|
41
|
-
function loadWallet() {
|
|
42
|
-
const key = process.env.WALLET;
|
|
43
|
-
if (!key)
|
|
44
|
-
throw new Error('Set WALLET env var to a base58-encoded private key');
|
|
45
|
-
return web3_js_1.Keypair.fromSecretKey(bs58_1.default.decode(key));
|
|
46
|
-
}
|
|
47
|
-
// ---------------------------------------------------------------------------
|
|
48
|
-
// mode: info
|
|
49
|
-
// ---------------------------------------------------------------------------
|
|
50
|
-
async function showLendingInfo(connection, mint) {
|
|
51
|
-
const token = await (0, torchsdk_1.getToken)(connection, mint);
|
|
52
|
-
const lending = await (0, torchsdk_1.getLendingInfo)(connection, mint);
|
|
53
|
-
console.log(`\n=== lending info: ${token.name} (${token.symbol}) ===`);
|
|
54
|
-
console.log(`status: ${token.status}`);
|
|
55
|
-
console.log(`token price: ${(0, utils_1.sol)(token.price_sol)} SOL`);
|
|
56
|
-
console.log(`interest rate: ${(0, utils_1.bpsToPercent)(lending.interest_rate_bps)}`);
|
|
57
|
-
console.log(`max LTV: ${(0, utils_1.bpsToPercent)(lending.max_ltv_bps)}`);
|
|
58
|
-
console.log(`liquidation threshold: ${(0, utils_1.bpsToPercent)(lending.liquidation_threshold_bps)}`);
|
|
59
|
-
console.log(`liquidation bonus: ${(0, utils_1.bpsToPercent)(lending.liquidation_bonus_bps)}`);
|
|
60
|
-
console.log(`treasury SOL avail: ${(0, utils_1.sol)(lending.treasury_sol_available)} SOL`);
|
|
61
|
-
console.log(`total SOL lent: ${(0, utils_1.sol)(lending.total_sol_lent)} SOL`);
|
|
62
|
-
console.log(`active loans: ${lending.active_loans}`);
|
|
63
|
-
}
|
|
64
|
-
async function showAllLending(connection) {
|
|
65
|
-
console.log('=== torch lending monitor ===\n');
|
|
66
|
-
console.log('no MINT specified — showing all migrated tokens with lending\n');
|
|
67
|
-
const { tokens } = await (0, torchsdk_1.getTokens)(connection, {
|
|
68
|
-
status: 'migrated',
|
|
69
|
-
sort: 'volume',
|
|
70
|
-
limit: 10,
|
|
71
|
-
});
|
|
72
|
-
for (const t of tokens) {
|
|
73
|
-
try {
|
|
74
|
-
const lending = await (0, torchsdk_1.getLendingInfo)(connection, t.mint);
|
|
75
|
-
console.log(`${t.symbol.padEnd(10)} | ` +
|
|
76
|
-
`rate: ${(0, utils_1.bpsToPercent)(lending.interest_rate_bps).padEnd(7)} | ` +
|
|
77
|
-
`loans: ${String(lending.active_loans).padEnd(4)} | ` +
|
|
78
|
-
`avail: ${(0, utils_1.sol)(lending.treasury_sol_available)} SOL`);
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
// token may not have lending enabled yet
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// ---------------------------------------------------------------------------
|
|
86
|
-
// mode: watch
|
|
87
|
-
// ---------------------------------------------------------------------------
|
|
88
|
-
async function watchPosition(connection, mint, wallet) {
|
|
89
|
-
const pollMs = Number(process.env.POLL_INTERVAL_MS ?? '15000');
|
|
90
|
-
console.log(`\n=== watching loan: ${wallet.publicKey.toBase58()} ===`);
|
|
91
|
-
console.log(`mint: ${mint}\n`);
|
|
92
|
-
while (true) {
|
|
93
|
-
const pos = await (0, torchsdk_1.getLoanPosition)(connection, mint, wallet.publicKey.toBase58());
|
|
94
|
-
if (pos.health === 'none') {
|
|
95
|
-
console.log(`[${new Date().toISOString()}] no active loan`);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
const healthColor = pos.health === 'healthy' ? 'OK' : pos.health === 'at_risk' ? 'WARNING' : 'DANGER';
|
|
99
|
-
console.log(`[${new Date().toISOString()}] health: ${healthColor} (${pos.health})`);
|
|
100
|
-
console.log(` collateral: ${pos.collateral_amount} tokens`);
|
|
101
|
-
console.log(` collat value: ${(0, utils_1.sol)(pos.collateral_value_sol)} SOL`);
|
|
102
|
-
console.log(` borrowed: ${(0, utils_1.sol)(pos.borrowed_amount)} SOL`);
|
|
103
|
-
console.log(` interest: ${(0, utils_1.sol)(pos.accrued_interest)} SOL`);
|
|
104
|
-
console.log(` total owed: ${(0, utils_1.sol)(pos.total_owed)} SOL`);
|
|
105
|
-
console.log(` current LTV: ${(0, utils_1.bpsToPercent)(pos.current_ltv_bps)}`);
|
|
106
|
-
if (pos.health === 'at_risk') {
|
|
107
|
-
console.log(' --> consider adding collateral or repaying to avoid liquidation');
|
|
108
|
-
}
|
|
109
|
-
if (pos.health === 'liquidatable') {
|
|
110
|
-
console.log(' --> your position can be liquidated! repay immediately');
|
|
111
|
-
if (process.env.AUTO_REPAY === 'true') {
|
|
112
|
-
console.log(' --> auto-repaying...');
|
|
113
|
-
const { transaction, message } = await (0, torchsdk_1.buildRepayTransaction)(connection, {
|
|
114
|
-
mint,
|
|
115
|
-
borrower: wallet.publicKey.toBase58(),
|
|
116
|
-
sol_amount: pos.total_owed,
|
|
117
|
-
});
|
|
118
|
-
console.log(` tx: ${message}`);
|
|
119
|
-
const sig = await (0, web3_js_1.sendAndConfirmTransaction)(connection, transaction, [wallet]);
|
|
120
|
-
console.log(` confirmed: ${sig}`);
|
|
121
|
-
const result = await (0, torchsdk_1.confirmTransaction)(connection, sig, wallet.publicKey.toBase58());
|
|
122
|
-
console.log(` SAID event: ${result.event_type}`);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
await (0, utils_1.sleep)(pollMs);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
// ---------------------------------------------------------------------------
|
|
130
|
-
// main
|
|
131
|
-
// ---------------------------------------------------------------------------
|
|
132
|
-
async function main() {
|
|
133
|
-
const MODE = process.env.MODE ?? 'info';
|
|
134
|
-
const MINT = process.env.MINT;
|
|
135
|
-
const RPC_URL = process.env.RPC_URL ?? 'https://api.mainnet-beta.solana.com';
|
|
136
|
-
// info mode: no wallet needed
|
|
137
|
-
if (MODE === 'info') {
|
|
138
|
-
const connection = new web3_js_1.Connection(RPC_URL, 'confirmed');
|
|
139
|
-
if (MINT) {
|
|
140
|
-
await showLendingInfo(connection, MINT);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
await showAllLending(connection);
|
|
144
|
-
}
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
// watch mode: single token + wallet
|
|
148
|
-
if (MODE === 'watch') {
|
|
149
|
-
if (!MINT)
|
|
150
|
-
throw new Error('MINT env var required for watch mode');
|
|
151
|
-
const connection = new web3_js_1.Connection(RPC_URL, 'confirmed');
|
|
152
|
-
await watchPosition(connection, MINT, loadWallet());
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
// bot mode: full liquidation bot
|
|
156
|
-
if (MODE === 'bot') {
|
|
157
|
-
const config = (0, config_1.loadConfig)();
|
|
158
|
-
const connection = new web3_js_1.Connection(config.rpcUrl, 'confirmed');
|
|
159
|
-
const monitor = new monitor_1.Monitor(connection, config);
|
|
160
|
-
// graceful shutdown
|
|
161
|
-
process.on('SIGINT', () => {
|
|
162
|
-
monitor.stop();
|
|
163
|
-
process.exit(0);
|
|
164
|
-
});
|
|
165
|
-
await monitor.start();
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
console.error(`unknown MODE: ${MODE}. use info | watch | bot`);
|
|
169
|
-
process.exit(1);
|
|
170
|
-
}
|
|
171
|
-
main();
|
|
172
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AACA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;;;AAEH,6CAAgF;AAChF,gDAAuB;AACvB,uCASiB;AACjB,uCAAmC;AACnC,qCAAqC;AACrC,mCAAkD;AAElD,8EAA8E;AAC9E,wDAAwD;AACxD,8EAA8E;AAE9E,SAAS,UAAU;IACjB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAA;IAC9B,IAAI,CAAC,GAAG;QA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,EAAE,CAAA;YACd,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC,CAAC,CAAA;QAEF,MAAM,OAAO,CAAC,KAAK,EAAE,CAAA;QACrB,OAAM;IACR,CAAC;IAED,OAAO,CAAC,KAAK,CAAC,iBAAiB,IAAI,0BAA0B,CAAC,CAAA;IAC9D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC;AAED,IAAI,EAAE,CAAA"}
|
package/dist/liquidator.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* liquidator.ts — executes liquidation transactions.
|
|
3
|
-
*
|
|
4
|
-
* receives a target, calculates expected profit, builds the tx,
|
|
5
|
-
* signs and sends it, then confirms via SAID for reputation.
|
|
6
|
-
*/
|
|
7
|
-
import { type Connection } from '@solana/web3.js';
|
|
8
|
-
import type { ScoredLoan, LiquidationResult, BotConfig } from './types';
|
|
9
|
-
import type { Logger } from './logger';
|
|
10
|
-
export declare class Liquidator {
|
|
11
|
-
private log;
|
|
12
|
-
private wallet;
|
|
13
|
-
private minProfitLamports;
|
|
14
|
-
constructor(config: BotConfig, log: Logger);
|
|
15
|
-
tryLiquidate(connection: Connection, loan: ScoredLoan): Promise<LiquidationResult | null>;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=liquidator.d.ts.map
|
package/dist/liquidator.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"liquidator.d.ts","sourceRoot":"","sources":["../src/liquidator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,UAAU,EAA2C,MAAM,iBAAiB,CAAA;AAE1F,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAGtC,qBAAa,UAAU;IACrB,OAAO,CAAC,GAAG,CAAQ;IACnB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,iBAAiB,CAAQ;gBAErB,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM;IAMpC,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;CA4DhG"}
|
package/dist/liquidator.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* liquidator.ts — executes liquidation transactions.
|
|
4
|
-
*
|
|
5
|
-
* receives a target, calculates expected profit, builds the tx,
|
|
6
|
-
* signs and sends it, then confirms via SAID for reputation.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.Liquidator = void 0;
|
|
10
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
11
|
-
const torchsdk_1 = require("torchsdk");
|
|
12
|
-
const utils_1 = require("./utils");
|
|
13
|
-
class Liquidator {
|
|
14
|
-
constructor(config, log) {
|
|
15
|
-
this.wallet = config.walletKeypair;
|
|
16
|
-
this.minProfitLamports = config.minProfitLamports;
|
|
17
|
-
this.log = log;
|
|
18
|
-
}
|
|
19
|
-
async tryLiquidate(connection, loan) {
|
|
20
|
-
if (loan.position.health !== 'liquidatable') {
|
|
21
|
-
this.log.debug(`skipping ${loan.borrower.slice(0, 8)}... — not liquidatable yet`);
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
if (loan.estimatedProfitLamports < this.minProfitLamports) {
|
|
25
|
-
this.log.debug(`skipping ${loan.borrower.slice(0, 8)}... — profit too low`, {
|
|
26
|
-
expected: (0, utils_1.sol)(loan.estimatedProfitLamports),
|
|
27
|
-
minimum: (0, utils_1.sol)(this.minProfitLamports),
|
|
28
|
-
});
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
this.log.info(`liquidating ${loan.borrower.slice(0, 8)}...`, {
|
|
32
|
-
token: loan.tokenName,
|
|
33
|
-
profit: `${(0, utils_1.sol)(loan.estimatedProfitLamports)} SOL`,
|
|
34
|
-
risk: loan.riskScore,
|
|
35
|
-
});
|
|
36
|
-
try {
|
|
37
|
-
const { transaction, message } = await (0, torchsdk_1.buildLiquidateTransaction)(connection, {
|
|
38
|
-
mint: loan.mint,
|
|
39
|
-
liquidator: this.wallet.publicKey.toBase58(),
|
|
40
|
-
borrower: loan.borrower,
|
|
41
|
-
});
|
|
42
|
-
this.log.debug(`tx built: ${message}`);
|
|
43
|
-
const signature = await (0, web3_js_1.sendAndConfirmTransaction)(connection, transaction, [this.wallet]);
|
|
44
|
-
this.log.info(`liquidation confirmed`, { sig: signature });
|
|
45
|
-
// confirm via SAID for reputation
|
|
46
|
-
let confirmed = false;
|
|
47
|
-
try {
|
|
48
|
-
const result = await (0, torchsdk_1.confirmTransaction)(connection, signature, this.wallet.publicKey.toBase58());
|
|
49
|
-
confirmed = result.confirmed;
|
|
50
|
-
this.log.debug(`SAID confirmation`, { event: result.event_type });
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
this.log.warn('SAID confirmation failed — tx still went through');
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
mint: loan.mint,
|
|
57
|
-
borrower: loan.borrower,
|
|
58
|
-
signature,
|
|
59
|
-
profitLamports: loan.estimatedProfitLamports,
|
|
60
|
-
timestamp: Date.now(),
|
|
61
|
-
confirmed,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
catch (err) {
|
|
65
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
66
|
-
this.log.error(`liquidation failed for ${loan.borrower.slice(0, 8)}...`, { error: msg });
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.Liquidator = Liquidator;
|
|
72
|
-
//# sourceMappingURL=liquidator.js.map
|
package/dist/liquidator.js.map
DELETED
|
@@ -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CAAC,uBAAuB;gBAC5C,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;gBACrB,SAAS;aACV,CAAA;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;YAC5D,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,0BAA0B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;YACxF,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC;CACF;AAvED,gCAuEC"}
|
package/dist/logger.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* logger.ts — simple structured logging with levels.
|
|
3
|
-
*/
|
|
4
|
-
import type { LogLevel } from './types';
|
|
5
|
-
export declare class Logger {
|
|
6
|
-
private module;
|
|
7
|
-
private minLevel;
|
|
8
|
-
constructor(module: string, level: LogLevel);
|
|
9
|
-
debug(msg: string, data?: Record<string, unknown>): void;
|
|
10
|
-
info(msg: string, data?: Record<string, unknown>): void;
|
|
11
|
-
warn(msg: string, data?: Record<string, unknown>): void;
|
|
12
|
-
error(msg: string, data?: Record<string, unknown>): void;
|
|
13
|
-
child(module: string): Logger;
|
|
14
|
-
private levelName;
|
|
15
|
-
private log;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=logger.d.ts.map
|
package/dist/logger.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AASvC,qBAAa,MAAM;IAIf,OAAO,CAAC,MAAM;IAHhB,OAAO,CAAC,QAAQ,CAAQ;gBAGd,MAAM,EAAE,MAAM,EACtB,KAAK,EAAE,QAAQ;IAKjB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIjD,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIhD,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIhD,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIjD,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAI7B,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,GAAG;CAeZ"}
|