@gearbox-protocol/sdk 9.10.8 → 9.11.0
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/dist/cjs/plugins/accounts/AccountsPlugin.js +86 -0
- package/dist/cjs/plugins/accounts/index.js +22 -0
- package/dist/cjs/plugins/accounts/package.json +1 -0
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +5 -5
- package/dist/esm/plugins/accounts/AccountsPlugin.js +66 -0
- package/dist/esm/plugins/accounts/index.js +1 -0
- package/dist/esm/plugins/accounts/package.json +1 -0
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +5 -5
- package/dist/types/plugins/accounts/AccountsPlugin.d.ts +20 -0
- package/dist/types/plugins/accounts/index.d.ts +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var AccountsPlugin_exports = {};
|
|
20
|
+
__export(AccountsPlugin_exports, {
|
|
21
|
+
AccountsPlugin: () => AccountsPlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(AccountsPlugin_exports);
|
|
24
|
+
var import_sdk = require("../../sdk/index.js");
|
|
25
|
+
class AccountsPlugin extends import_sdk.BasePlugin {
|
|
26
|
+
#accounts;
|
|
27
|
+
#byCreditManager;
|
|
28
|
+
#byPool;
|
|
29
|
+
#options;
|
|
30
|
+
constructor(options = {}, loadOnAttach = true) {
|
|
31
|
+
super(loadOnAttach);
|
|
32
|
+
this.#options = options;
|
|
33
|
+
}
|
|
34
|
+
get accounts() {
|
|
35
|
+
if (!this.#accounts) {
|
|
36
|
+
throw new Error("AccountsPlugin is not loaded");
|
|
37
|
+
}
|
|
38
|
+
return this.#accounts;
|
|
39
|
+
}
|
|
40
|
+
get loaded() {
|
|
41
|
+
return !!this.#accounts;
|
|
42
|
+
}
|
|
43
|
+
byCreditManager(creditManager) {
|
|
44
|
+
return this.#byCreditManager?.get(creditManager) ?? [];
|
|
45
|
+
}
|
|
46
|
+
byPool(pool) {
|
|
47
|
+
return this.#byPool?.get(pool) ?? [];
|
|
48
|
+
}
|
|
49
|
+
async load(force) {
|
|
50
|
+
if (!force && this.loaded) {
|
|
51
|
+
return this.state;
|
|
52
|
+
}
|
|
53
|
+
const service = (0, import_sdk.createCreditAccountService)(this.sdk, 310);
|
|
54
|
+
const accounts = await service.getCreditAccounts(
|
|
55
|
+
this.#options,
|
|
56
|
+
this.sdk.currentBlock
|
|
57
|
+
);
|
|
58
|
+
this.#setAccounts(accounts);
|
|
59
|
+
return this.state;
|
|
60
|
+
}
|
|
61
|
+
get state() {
|
|
62
|
+
return {
|
|
63
|
+
accounts: this.accounts
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
hydrate(state) {
|
|
67
|
+
this.#setAccounts(state.accounts);
|
|
68
|
+
}
|
|
69
|
+
#setAccounts(accounts) {
|
|
70
|
+
this.#accounts = accounts;
|
|
71
|
+
this.#byCreditManager = new import_sdk.AddressMap();
|
|
72
|
+
this.#byPool = new import_sdk.AddressMap();
|
|
73
|
+
for (const a of accounts) {
|
|
74
|
+
const { creditManager } = a;
|
|
75
|
+
const cmAccounts = this.#byCreditManager.get(creditManager) ?? [];
|
|
76
|
+
this.#byCreditManager.upsert(creditManager, [...cmAccounts, a]);
|
|
77
|
+
const pool = this.sdk.marketRegister.findByCreditManager(creditManager).pool.pool.address;
|
|
78
|
+
const poolAccounts = this.#byPool.get(pool) ?? [];
|
|
79
|
+
this.#byPool.upsert(pool, [...poolAccounts, a]);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
AccountsPlugin
|
|
86
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var accounts_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(accounts_exports);
|
|
18
|
+
__reExport(accounts_exports, require("./AccountsPlugin.js"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./AccountsPlugin.js")
|
|
22
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "commonjs"}
|
|
@@ -32,7 +32,6 @@ var import_constants = require("../constants/index.js");
|
|
|
32
32
|
var import_router = require("../router/index.js");
|
|
33
33
|
var import_utils = require("../utils/index.js");
|
|
34
34
|
var import_viem2 = require("../utils/viem/index.js");
|
|
35
|
-
var import_utils2 = require("./utils.js");
|
|
36
35
|
class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
37
36
|
#compressor;
|
|
38
37
|
#batchSize;
|
|
@@ -127,8 +126,10 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
127
126
|
ignoreReservePrices ? { main: true } : void 0
|
|
128
127
|
);
|
|
129
128
|
const allCAs = [];
|
|
129
|
+
let revertingOffset = 0;
|
|
130
130
|
for (const reverting of [false, true]) {
|
|
131
131
|
let offset = 0n;
|
|
132
|
+
revertingOffset = allCAs.length;
|
|
132
133
|
do {
|
|
133
134
|
const [accounts, newOffset] = await this.#getCreditAccounts(
|
|
134
135
|
this.#batchSize ? [
|
|
@@ -145,6 +146,9 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
145
146
|
offset = newOffset;
|
|
146
147
|
} while (offset !== 0n);
|
|
147
148
|
}
|
|
149
|
+
this.#logger?.debug(
|
|
150
|
+
`loaded ${allCAs.length} credit accounts (${allCAs.length - revertingOffset} reverting)`
|
|
151
|
+
);
|
|
148
152
|
return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
149
153
|
}
|
|
150
154
|
/**
|
|
@@ -755,10 +759,6 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
755
759
|
* @returns
|
|
756
760
|
*/
|
|
757
761
|
async #getCreditAccounts(args, priceUpdateTxs, blockNumber) {
|
|
758
|
-
this.#logger?.debug(
|
|
759
|
-
{ args: (0, import_utils2.stringifyGetCreditAccountsArgs)(args) },
|
|
760
|
-
"getting credit accounts"
|
|
761
|
-
);
|
|
762
762
|
let resp;
|
|
763
763
|
if (priceUpdateTxs?.length) {
|
|
764
764
|
[resp] = await (0, import_viem2.simulateWithPriceUpdates)(this.client, {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AddressMap,
|
|
3
|
+
BasePlugin,
|
|
4
|
+
createCreditAccountService
|
|
5
|
+
} from "../../sdk/index.js";
|
|
6
|
+
class AccountsPlugin extends BasePlugin {
|
|
7
|
+
#accounts;
|
|
8
|
+
#byCreditManager;
|
|
9
|
+
#byPool;
|
|
10
|
+
#options;
|
|
11
|
+
constructor(options = {}, loadOnAttach = true) {
|
|
12
|
+
super(loadOnAttach);
|
|
13
|
+
this.#options = options;
|
|
14
|
+
}
|
|
15
|
+
get accounts() {
|
|
16
|
+
if (!this.#accounts) {
|
|
17
|
+
throw new Error("AccountsPlugin is not loaded");
|
|
18
|
+
}
|
|
19
|
+
return this.#accounts;
|
|
20
|
+
}
|
|
21
|
+
get loaded() {
|
|
22
|
+
return !!this.#accounts;
|
|
23
|
+
}
|
|
24
|
+
byCreditManager(creditManager) {
|
|
25
|
+
return this.#byCreditManager?.get(creditManager) ?? [];
|
|
26
|
+
}
|
|
27
|
+
byPool(pool) {
|
|
28
|
+
return this.#byPool?.get(pool) ?? [];
|
|
29
|
+
}
|
|
30
|
+
async load(force) {
|
|
31
|
+
if (!force && this.loaded) {
|
|
32
|
+
return this.state;
|
|
33
|
+
}
|
|
34
|
+
const service = createCreditAccountService(this.sdk, 310);
|
|
35
|
+
const accounts = await service.getCreditAccounts(
|
|
36
|
+
this.#options,
|
|
37
|
+
this.sdk.currentBlock
|
|
38
|
+
);
|
|
39
|
+
this.#setAccounts(accounts);
|
|
40
|
+
return this.state;
|
|
41
|
+
}
|
|
42
|
+
get state() {
|
|
43
|
+
return {
|
|
44
|
+
accounts: this.accounts
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
hydrate(state) {
|
|
48
|
+
this.#setAccounts(state.accounts);
|
|
49
|
+
}
|
|
50
|
+
#setAccounts(accounts) {
|
|
51
|
+
this.#accounts = accounts;
|
|
52
|
+
this.#byCreditManager = new AddressMap();
|
|
53
|
+
this.#byPool = new AddressMap();
|
|
54
|
+
for (const a of accounts) {
|
|
55
|
+
const { creditManager } = a;
|
|
56
|
+
const cmAccounts = this.#byCreditManager.get(creditManager) ?? [];
|
|
57
|
+
this.#byCreditManager.upsert(creditManager, [...cmAccounts, a]);
|
|
58
|
+
const pool = this.sdk.marketRegister.findByCreditManager(creditManager).pool.pool.address;
|
|
59
|
+
const poolAccounts = this.#byPool.get(pool) ?? [];
|
|
60
|
+
this.#byPool.upsert(pool, [...poolAccounts, a]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
AccountsPlugin
|
|
66
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./AccountsPlugin.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "module","sideEffects":false}
|
|
@@ -27,7 +27,6 @@ import {
|
|
|
27
27
|
import { assetsMap } from "../router/index.js";
|
|
28
28
|
import { AddressMap, childLogger } from "../utils/index.js";
|
|
29
29
|
import { simulateWithPriceUpdates } from "../utils/viem/index.js";
|
|
30
|
-
import { stringifyGetCreditAccountsArgs } from "./utils.js";
|
|
31
30
|
class AbstractCreditAccountService extends SDKConstruct {
|
|
32
31
|
#compressor;
|
|
33
32
|
#batchSize;
|
|
@@ -122,8 +121,10 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
122
121
|
ignoreReservePrices ? { main: true } : void 0
|
|
123
122
|
);
|
|
124
123
|
const allCAs = [];
|
|
124
|
+
let revertingOffset = 0;
|
|
125
125
|
for (const reverting of [false, true]) {
|
|
126
126
|
let offset = 0n;
|
|
127
|
+
revertingOffset = allCAs.length;
|
|
127
128
|
do {
|
|
128
129
|
const [accounts, newOffset] = await this.#getCreditAccounts(
|
|
129
130
|
this.#batchSize ? [
|
|
@@ -140,6 +141,9 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
140
141
|
offset = newOffset;
|
|
141
142
|
} while (offset !== 0n);
|
|
142
143
|
}
|
|
144
|
+
this.#logger?.debug(
|
|
145
|
+
`loaded ${allCAs.length} credit accounts (${allCAs.length - revertingOffset} reverting)`
|
|
146
|
+
);
|
|
143
147
|
return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
144
148
|
}
|
|
145
149
|
/**
|
|
@@ -750,10 +754,6 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
750
754
|
* @returns
|
|
751
755
|
*/
|
|
752
756
|
async #getCreditAccounts(args, priceUpdateTxs, blockNumber) {
|
|
753
|
-
this.#logger?.debug(
|
|
754
|
-
{ args: stringifyGetCreditAccountsArgs(args) },
|
|
755
|
-
"getting credit accounts"
|
|
756
|
-
);
|
|
757
757
|
let resp;
|
|
758
758
|
if (priceUpdateTxs?.length) {
|
|
759
759
|
[resp] = await simulateWithPriceUpdates(this.client, {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { CreditAccountData, GetCreditAccountsOptions, IGearboxSDKPlugin } from "../../sdk/index.js";
|
|
3
|
+
import { BasePlugin } from "../../sdk/index.js";
|
|
4
|
+
export interface AccountsPluginState {
|
|
5
|
+
/**
|
|
6
|
+
* All credit accounts
|
|
7
|
+
*/
|
|
8
|
+
accounts: CreditAccountData[];
|
|
9
|
+
}
|
|
10
|
+
export declare class AccountsPlugin extends BasePlugin<AccountsPluginState> implements IGearboxSDKPlugin<AccountsPluginState> {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(options?: GetCreditAccountsOptions, loadOnAttach?: boolean);
|
|
13
|
+
get accounts(): CreditAccountData[];
|
|
14
|
+
get loaded(): boolean;
|
|
15
|
+
byCreditManager(creditManager: Address): CreditAccountData[];
|
|
16
|
+
byPool(pool: Address): CreditAccountData[];
|
|
17
|
+
load(force?: boolean): Promise<AccountsPluginState>;
|
|
18
|
+
get state(): AccountsPluginState;
|
|
19
|
+
hydrate(state: AccountsPluginState): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./AccountsPlugin.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.11.0",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/cjs/sdk/index.js",
|
|
@@ -73,11 +73,11 @@
|
|
|
73
73
|
"cross-spawn": "^7.0.6",
|
|
74
74
|
"husky": "^9.1.7",
|
|
75
75
|
"lint-staged": "^16.2.3",
|
|
76
|
-
"pino": "^
|
|
76
|
+
"pino": "^10.0.0",
|
|
77
77
|
"pino-pretty": "^13.1.1",
|
|
78
78
|
"tsup": "^8.5.0",
|
|
79
79
|
"tsx": "^4.20.6",
|
|
80
|
-
"typescript": "^5.9.
|
|
80
|
+
"typescript": "^5.9.3",
|
|
81
81
|
"viem-deal": "^2.0.4",
|
|
82
82
|
"vitest": "^3.2.4"
|
|
83
83
|
},
|