@gearbox-protocol/sdk 13.5.1 → 13.6.0-apy-plugin.1
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/pools-history/ApyPlugin.js +328 -0
- package/dist/cjs/plugins/pools-history/apy-cache.js +120 -0
- package/dist/cjs/plugins/pools-history/apy-parser.js +169 -0
- package/dist/cjs/plugins/pools-history/constants.js +31 -0
- package/dist/cjs/plugins/pools-history/index.js +12 -2
- package/dist/cjs/plugins/pools-history/pool-apy-types.js +16 -0
- package/dist/cjs/plugins/pools-history/pool-apy-utils.js +141 -0
- package/dist/cjs/rewards/rewards/extra-apy.js +10 -8
- package/dist/cjs/sdk/GearboxSDK.js +11 -0
- package/dist/esm/plugins/pools-history/ApyPlugin.js +317 -0
- package/dist/esm/plugins/pools-history/apy-cache.js +86 -0
- package/dist/esm/plugins/pools-history/apy-parser.js +143 -0
- package/dist/esm/plugins/pools-history/constants.js +6 -0
- package/dist/esm/plugins/pools-history/index.js +6 -1
- package/dist/esm/plugins/pools-history/pool-apy-types.js +0 -0
- package/dist/esm/plugins/pools-history/pool-apy-utils.js +113 -0
- package/dist/esm/rewards/rewards/extra-apy.js +10 -8
- package/dist/esm/sdk/GearboxSDK.js +11 -0
- package/dist/types/plugins/pools-history/ApyPlugin.d.ts +70 -0
- package/dist/types/plugins/pools-history/apy-cache.d.ts +28 -0
- package/dist/types/plugins/pools-history/apy-parser.d.ts +5 -0
- package/dist/types/plugins/pools-history/constants.d.ts +2 -0
- package/dist/types/plugins/pools-history/index.d.ts +6 -1
- package/dist/types/plugins/pools-history/pool-apy-types.d.ts +39 -0
- package/dist/types/plugins/pools-history/pool-apy-utils.d.ts +71 -0
- package/dist/types/plugins/pools-history/types.d.ts +28 -0
- package/dist/types/rewards/rewards/api.d.ts +10 -1
- package/dist/types/rewards/rewards/common.d.ts +0 -10
- package/dist/types/rewards/rewards/extra-apy.d.ts +4 -6
- package/dist/types/sdk/GearboxSDK.d.ts +19 -0
- package/dist/types/sdk/base/types.d.ts +0 -9
- package/package.json +1 -1
- package/dist/cjs/plugins/pools-history/Pools7DAgoPlugin.js +0 -108
- package/dist/esm/plugins/pools-history/Pools7DAgoPlugin.js +0 -90
- package/dist/types/plugins/pools-history/Pools7DAgoPlugin.d.ts +0 -20
|
@@ -115,6 +115,13 @@ export interface SyncStateOptions {
|
|
|
115
115
|
**/
|
|
116
116
|
ignoreUpdateablePrices?: boolean;
|
|
117
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Payload carried by the `pluginUpdate` hook.
|
|
120
|
+
**/
|
|
121
|
+
export interface PluginUpdateInfo {
|
|
122
|
+
/** Identifier of the plugin that triggered the update (e.g. `"pools7DAgo"`). */
|
|
123
|
+
plugin: string;
|
|
124
|
+
}
|
|
118
125
|
/**
|
|
119
126
|
* Hook event map for the SDK lifecycle.
|
|
120
127
|
*
|
|
@@ -123,10 +130,13 @@ export interface SyncStateOptions {
|
|
|
123
130
|
*
|
|
124
131
|
* - `syncState` — fired after {@link GearboxSDK.syncState} completes.
|
|
125
132
|
* - `rehydrate` — fired after {@link GearboxSDK.rehydrate} completes.
|
|
133
|
+
* - `pluginUpdate` — fired by a plugin when its internal state changes
|
|
134
|
+
* outside of the normal `syncState`/`rehydrate` cycle (e.g. timer tick).
|
|
126
135
|
**/
|
|
127
136
|
export type SDKHooks = {
|
|
128
137
|
syncState: [SyncStateOptions];
|
|
129
138
|
rehydrate: [SyncStateOptions];
|
|
139
|
+
pluginUpdate: [PluginUpdateInfo];
|
|
130
140
|
};
|
|
131
141
|
/**
|
|
132
142
|
* Main entry point for the Gearbox SDK.
|
|
@@ -175,6 +185,15 @@ export declare class GearboxSDK<const Plugins extends PluginsMap = {}> extends C
|
|
|
175
185
|
* @see {@link SDKHooks} for available event names.
|
|
176
186
|
**/
|
|
177
187
|
removeHook: <K extends keyof SDKHooks>(hookName: K, fn: (...args: SDKHooks[K]) => void | Promise<void>) => void;
|
|
188
|
+
/**
|
|
189
|
+
* Triggers the `pluginUpdate` hook.
|
|
190
|
+
*
|
|
191
|
+
* Intended to be called by plugins when they update their internal state
|
|
192
|
+
* outside of the normal `syncState`/`rehydrate` cycle (e.g. via an
|
|
193
|
+
* internal timer). Frontend listeners registered with
|
|
194
|
+
* `sdk.addHook("pluginUpdate", …)` will be notified.
|
|
195
|
+
**/
|
|
196
|
+
triggerPluginUpdate(plugin: string): Promise<void>;
|
|
178
197
|
/**
|
|
179
198
|
* Creates and initialises a new SDK instance by reading live on-chain state.
|
|
180
199
|
*
|
|
@@ -5,7 +5,6 @@ import type { gaugeCompressorAbi } from "../../abi/compressors/gaugeCompressor.j
|
|
|
5
5
|
import type { marketCompressorAbi } from "../../abi/compressors/marketCompressor.js";
|
|
6
6
|
import type { peripheryCompressorAbi } from "../../abi/compressors/peripheryCompressor.js";
|
|
7
7
|
import type { rewardsCompressorAbi } from "../../abi/compressors/rewardsCompressor.js";
|
|
8
|
-
import type { NetworkType } from "../chain/index.js";
|
|
9
8
|
/**
|
|
10
9
|
* Recursively unwraps array types to their element type.
|
|
11
10
|
**/
|
|
@@ -245,14 +244,6 @@ export interface IBaseContract {
|
|
|
245
244
|
* labeling methods for user-facing output.
|
|
246
245
|
*/
|
|
247
246
|
readonly name: string;
|
|
248
|
-
/**
|
|
249
|
-
* Chain ID of the contract.
|
|
250
|
-
**/
|
|
251
|
-
readonly chainId: number;
|
|
252
|
-
/**
|
|
253
|
-
* Network type of the contract.
|
|
254
|
-
**/
|
|
255
|
-
readonly networkType: NetworkType;
|
|
256
247
|
/**
|
|
257
248
|
* @internal
|
|
258
249
|
* `true` when the local state has diverged from on-chain and needs a sync.
|
package/package.json
CHANGED
|
@@ -1,108 +0,0 @@
|
|
|
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 Pools7DAgoPlugin_exports = {};
|
|
20
|
-
__export(Pools7DAgoPlugin_exports, {
|
|
21
|
-
Pools7DAgoPlugin: () => Pools7DAgoPlugin
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(Pools7DAgoPlugin_exports);
|
|
24
|
-
var import_marketCompressor = require("../../abi/compressors/marketCompressor.js");
|
|
25
|
-
var import_sdk = require("../../sdk/index.js");
|
|
26
|
-
const MAP_LABEL = "pools7DAgo";
|
|
27
|
-
class Pools7DAgoPlugin extends import_sdk.BasePlugin {
|
|
28
|
-
#pools7DAgo;
|
|
29
|
-
async load(force) {
|
|
30
|
-
if (!force && this.loaded) {
|
|
31
|
-
return this.state;
|
|
32
|
-
}
|
|
33
|
-
const targetBlock = this.sdk.currentBlock - import_sdk.BLOCKS_PER_WEEK_BY_NETWORK[this.sdk.networkType];
|
|
34
|
-
const [marketCompressorAddress] = this.sdk.addressProvider.mustGetLatest(
|
|
35
|
-
import_sdk.AP_MARKET_COMPRESSOR,
|
|
36
|
-
import_sdk.VERSION_RANGE_310
|
|
37
|
-
);
|
|
38
|
-
this.sdk.logger?.debug(
|
|
39
|
-
`loading pools 7d ago with market compressor ${marketCompressorAddress}`
|
|
40
|
-
);
|
|
41
|
-
const markets = this.sdk.marketRegister.markets;
|
|
42
|
-
const resp = await this.client.multicall({
|
|
43
|
-
allowFailure: true,
|
|
44
|
-
contracts: markets.map(
|
|
45
|
-
(m) => ({
|
|
46
|
-
address: marketCompressorAddress,
|
|
47
|
-
abi: import_marketCompressor.marketCompressorAbi,
|
|
48
|
-
functionName: "getPoolState",
|
|
49
|
-
args: [m.pool.pool.address]
|
|
50
|
-
})
|
|
51
|
-
),
|
|
52
|
-
blockNumber: targetBlock > 0n ? targetBlock : void 0,
|
|
53
|
-
batchSize: 0
|
|
54
|
-
});
|
|
55
|
-
this.#pools7DAgo = new import_sdk.AddressMap(void 0, MAP_LABEL);
|
|
56
|
-
resp.forEach((r, index) => {
|
|
57
|
-
const m = markets[index];
|
|
58
|
-
const cfg = m.configurator.address;
|
|
59
|
-
const pool = m.pool.pool.address;
|
|
60
|
-
if (r.status === "success") {
|
|
61
|
-
this.#pools7DAgo?.upsert(m.pool.pool.address, {
|
|
62
|
-
dieselRate: r.result.dieselRate,
|
|
63
|
-
pool
|
|
64
|
-
});
|
|
65
|
-
} else {
|
|
66
|
-
this.sdk.logger?.error(
|
|
67
|
-
`failed to load pools 7d ago for market configurator ${this.labelAddress(cfg)} and pool ${this.labelAddress(pool)}: ${r.error}`
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
return this.state;
|
|
72
|
-
}
|
|
73
|
-
get loaded() {
|
|
74
|
-
return !!this.#pools7DAgo;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Returns a map of pool addresses to minified pool 7d ago state
|
|
78
|
-
* @throws if pool 7d ago plugin is not attached
|
|
79
|
-
*/
|
|
80
|
-
get pools7DAgo() {
|
|
81
|
-
if (!this.#pools7DAgo) {
|
|
82
|
-
throw new Error("pools 7d ago plugin not attached");
|
|
83
|
-
}
|
|
84
|
-
return this.#pools7DAgo;
|
|
85
|
-
}
|
|
86
|
-
stateHuman(_) {
|
|
87
|
-
return this.pools7DAgo.values().flatMap((p) => ({
|
|
88
|
-
address: p.pool,
|
|
89
|
-
version: this.version,
|
|
90
|
-
dieselRate: p.dieselRate
|
|
91
|
-
}));
|
|
92
|
-
}
|
|
93
|
-
get state() {
|
|
94
|
-
return {
|
|
95
|
-
pools7DAgo: this.pools7DAgo.asRecord()
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
hydrate(state) {
|
|
99
|
-
this.#pools7DAgo = new import_sdk.AddressMap(
|
|
100
|
-
Object.entries(state.pools7DAgo),
|
|
101
|
-
MAP_LABEL
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
-
0 && (module.exports = {
|
|
107
|
-
Pools7DAgoPlugin
|
|
108
|
-
});
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { marketCompressorAbi } from "../../abi/compressors/marketCompressor.js";
|
|
2
|
-
import {
|
|
3
|
-
AddressMap,
|
|
4
|
-
AP_MARKET_COMPRESSOR,
|
|
5
|
-
BasePlugin,
|
|
6
|
-
BLOCKS_PER_WEEK_BY_NETWORK,
|
|
7
|
-
VERSION_RANGE_310
|
|
8
|
-
} from "../../sdk/index.js";
|
|
9
|
-
const MAP_LABEL = "pools7DAgo";
|
|
10
|
-
class Pools7DAgoPlugin extends BasePlugin {
|
|
11
|
-
#pools7DAgo;
|
|
12
|
-
async load(force) {
|
|
13
|
-
if (!force && this.loaded) {
|
|
14
|
-
return this.state;
|
|
15
|
-
}
|
|
16
|
-
const targetBlock = this.sdk.currentBlock - BLOCKS_PER_WEEK_BY_NETWORK[this.sdk.networkType];
|
|
17
|
-
const [marketCompressorAddress] = this.sdk.addressProvider.mustGetLatest(
|
|
18
|
-
AP_MARKET_COMPRESSOR,
|
|
19
|
-
VERSION_RANGE_310
|
|
20
|
-
);
|
|
21
|
-
this.sdk.logger?.debug(
|
|
22
|
-
`loading pools 7d ago with market compressor ${marketCompressorAddress}`
|
|
23
|
-
);
|
|
24
|
-
const markets = this.sdk.marketRegister.markets;
|
|
25
|
-
const resp = await this.client.multicall({
|
|
26
|
-
allowFailure: true,
|
|
27
|
-
contracts: markets.map(
|
|
28
|
-
(m) => ({
|
|
29
|
-
address: marketCompressorAddress,
|
|
30
|
-
abi: marketCompressorAbi,
|
|
31
|
-
functionName: "getPoolState",
|
|
32
|
-
args: [m.pool.pool.address]
|
|
33
|
-
})
|
|
34
|
-
),
|
|
35
|
-
blockNumber: targetBlock > 0n ? targetBlock : void 0,
|
|
36
|
-
batchSize: 0
|
|
37
|
-
});
|
|
38
|
-
this.#pools7DAgo = new AddressMap(void 0, MAP_LABEL);
|
|
39
|
-
resp.forEach((r, index) => {
|
|
40
|
-
const m = markets[index];
|
|
41
|
-
const cfg = m.configurator.address;
|
|
42
|
-
const pool = m.pool.pool.address;
|
|
43
|
-
if (r.status === "success") {
|
|
44
|
-
this.#pools7DAgo?.upsert(m.pool.pool.address, {
|
|
45
|
-
dieselRate: r.result.dieselRate,
|
|
46
|
-
pool
|
|
47
|
-
});
|
|
48
|
-
} else {
|
|
49
|
-
this.sdk.logger?.error(
|
|
50
|
-
`failed to load pools 7d ago for market configurator ${this.labelAddress(cfg)} and pool ${this.labelAddress(pool)}: ${r.error}`
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
return this.state;
|
|
55
|
-
}
|
|
56
|
-
get loaded() {
|
|
57
|
-
return !!this.#pools7DAgo;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Returns a map of pool addresses to minified pool 7d ago state
|
|
61
|
-
* @throws if pool 7d ago plugin is not attached
|
|
62
|
-
*/
|
|
63
|
-
get pools7DAgo() {
|
|
64
|
-
if (!this.#pools7DAgo) {
|
|
65
|
-
throw new Error("pools 7d ago plugin not attached");
|
|
66
|
-
}
|
|
67
|
-
return this.#pools7DAgo;
|
|
68
|
-
}
|
|
69
|
-
stateHuman(_) {
|
|
70
|
-
return this.pools7DAgo.values().flatMap((p) => ({
|
|
71
|
-
address: p.pool,
|
|
72
|
-
version: this.version,
|
|
73
|
-
dieselRate: p.dieselRate
|
|
74
|
-
}));
|
|
75
|
-
}
|
|
76
|
-
get state() {
|
|
77
|
-
return {
|
|
78
|
-
pools7DAgo: this.pools7DAgo.asRecord()
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
hydrate(state) {
|
|
82
|
-
this.#pools7DAgo = new AddressMap(
|
|
83
|
-
Object.entries(state.pools7DAgo),
|
|
84
|
-
MAP_LABEL
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
export {
|
|
89
|
-
Pools7DAgoPlugin
|
|
90
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Address } from "viem";
|
|
2
|
-
import type { IGearboxSDKPlugin } from "../../sdk/index.js";
|
|
3
|
-
import { AddressMap, BasePlugin } from "../../sdk/index.js";
|
|
4
|
-
import type { Pool7DAgoState, Pools7DAgoStateHuman } from "./types.js";
|
|
5
|
-
export interface Pools7DAgoPluginState {
|
|
6
|
-
pools7DAgo: Record<Address, Pool7DAgoState>;
|
|
7
|
-
}
|
|
8
|
-
export declare class Pools7DAgoPlugin extends BasePlugin<Pools7DAgoPluginState> implements IGearboxSDKPlugin<Pools7DAgoPluginState> {
|
|
9
|
-
#private;
|
|
10
|
-
load(force?: boolean): Promise<Pools7DAgoPluginState>;
|
|
11
|
-
get loaded(): boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Returns a map of pool addresses to minified pool 7d ago state
|
|
14
|
-
* @throws if pool 7d ago plugin is not attached
|
|
15
|
-
*/
|
|
16
|
-
get pools7DAgo(): AddressMap<Pool7DAgoState>;
|
|
17
|
-
stateHuman(_?: boolean): Pools7DAgoStateHuman[];
|
|
18
|
-
get state(): Pools7DAgoPluginState;
|
|
19
|
-
hydrate(state: Pools7DAgoPluginState): void;
|
|
20
|
-
}
|