@gearbox-protocol/sdk 16.0.0-next.54 → 16.0.0-next.55
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/dev/mode-parity/compareOpportunities.js +3 -4
- package/dist/cjs/dev/mode-parity/comparePositions.js +5 -6
- package/dist/cjs/dev/mode-parity/fieldDiff.js +4 -6
- package/dist/cjs/dev/mode-parity/scriptUtils.js +145 -5
- package/dist/cjs/rewards/errors.js +27 -0
- package/dist/cjs/rewards/index.js +6 -7
- package/dist/cjs/rewards/merkl-api.js +45 -0
- package/dist/cjs/rewards/multichain.js +40 -0
- package/dist/cjs/rewards/{rewards/api.js → toMerklRewards.js} +26 -28
- package/dist/esm/dev/mode-parity/compareOpportunities.js +3 -4
- package/dist/esm/dev/mode-parity/comparePositions.js +5 -6
- package/dist/esm/dev/mode-parity/fieldDiff.js +4 -6
- package/dist/esm/dev/mode-parity/scriptUtils.js +142 -6
- package/dist/esm/rewards/errors.js +26 -0
- package/dist/esm/rewards/index.js +4 -5
- package/dist/esm/rewards/merkl-api.js +42 -0
- package/dist/esm/rewards/multichain.js +39 -0
- package/dist/esm/rewards/{rewards/api.js → toMerklRewards.js} +26 -28
- package/dist/types/dev/mode-parity/compareOpportunities.d.ts +3 -7
- package/dist/types/dev/mode-parity/comparePositions.d.ts +4 -8
- package/dist/types/dev/mode-parity/fieldDiff.d.ts +9 -8
- package/dist/types/dev/mode-parity/scriptUtils.d.ts +26 -1
- package/dist/types/rewards/errors.d.ts +18 -0
- package/dist/types/rewards/index.d.ts +4 -7
- package/dist/types/rewards/merkl-api.d.ts +64 -0
- package/dist/types/rewards/multichain.d.ts +33 -0
- package/dist/types/rewards/toMerklRewards.d.ts +42 -0
- package/package.json +1 -3
- package/dist/cjs/_virtual/_rolldown/runtime.js +0 -23
- package/dist/cjs/rewards/apy/index.js +0 -3
- package/dist/cjs/rewards/apy/output-details.js +0 -1
- package/dist/cjs/rewards/apy/output.js +0 -1
- package/dist/cjs/rewards/rewards/common.js +0 -1
- package/dist/cjs/rewards/rewards/extra-apy.js +0 -71
- package/dist/cjs/rewards/rewards/index.js +0 -6
- package/dist/cjs/rewards/rewards/merkl-api.js +0 -22
- package/dist/esm/rewards/apy/index.js +0 -3
- package/dist/esm/rewards/apy/output-details.js +0 -1
- package/dist/esm/rewards/apy/output.js +0 -1
- package/dist/esm/rewards/rewards/common.js +0 -1
- package/dist/esm/rewards/rewards/extra-apy.js +0 -67
- package/dist/esm/rewards/rewards/index.js +0 -3
- package/dist/esm/rewards/rewards/merkl-api.js +0 -19
- package/dist/types/rewards/apy/index.d.ts +0 -3
- package/dist/types/rewards/apy/output-details.d.ts +0 -99
- package/dist/types/rewards/apy/output.d.ts +0 -25
- package/dist/types/rewards/rewards/api.d.ts +0 -60
- package/dist/types/rewards/rewards/common.d.ts +0 -9
- package/dist/types/rewards/rewards/extra-apy.d.ts +0 -37
- package/dist/types/rewards/rewards/index.d.ts +0 -3
- package/dist/types/rewards/rewards/merkl-api.d.ts +0 -54
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ChainId, Token, TokenAmount } from "../model/primitives.js";
|
|
2
|
+
import "../model/index.js";
|
|
3
|
+
import { OnchainSDK } from "../onchain/OnchainSDK.js";
|
|
4
|
+
import "../onchain/index.js";
|
|
5
|
+
import { MerkleXYZUserRewardsV4Response } from "./merkl-api.js";
|
|
6
|
+
import { Address } from "viem";
|
|
7
|
+
//#region src/rewards/toMerklRewards.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* One claimable Merkl liquidity-mining reward, denominated and priced.
|
|
10
|
+
*
|
|
11
|
+
* Both tokens arrive resolved, so a consumer neither looks one up nor
|
|
12
|
+
* reassembles one out of the loose fields Merkl sends.
|
|
13
|
+
*/
|
|
14
|
+
interface MerklReward {
|
|
15
|
+
readonly chainId: ChainId;
|
|
16
|
+
/** Market pool whose depositors the campaign rewards. */
|
|
17
|
+
readonly pool: Address;
|
|
18
|
+
/** That pool's share token — what the campaign is keyed on. */
|
|
19
|
+
readonly poolToken: Token;
|
|
20
|
+
/**
|
|
21
|
+
* The incentive token being handed out, how much of it is claimable
|
|
22
|
+
* (distributed minus already claimed, always > 0) and what that is worth.
|
|
23
|
+
*
|
|
24
|
+
* Priced by Merkl, not by the market oracles: a campaign's incentive token
|
|
25
|
+
* is rarely collateral in the pool it incentivises, so the oracles usually
|
|
26
|
+
* do not know it — GEAR, which most Gearbox campaigns pay in, among them.
|
|
27
|
+
* `valueUsd` is `null` for a token Merkl does not price either.
|
|
28
|
+
*/
|
|
29
|
+
readonly amount: TokenAmount;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* What the mapping needs off a chain's SDK: which chain the rows belong to,
|
|
33
|
+
* the pools a campaign can be keyed on, and the registry that names their
|
|
34
|
+
* tokens. Nothing else, and nothing asynchronous.
|
|
35
|
+
*/
|
|
36
|
+
type MerklRewardsSdk = Pick<OnchainSDK, "chainId" | "marketRegister" | "tokensMeta">;
|
|
37
|
+
/**
|
|
38
|
+
* Merkl's answer for one chain, turned into rows of the read model.
|
|
39
|
+
*/
|
|
40
|
+
declare function toMerklRewards(sdk: MerklRewardsSdk, response: MerkleXYZUserRewardsV4Response): MerklReward[];
|
|
41
|
+
//#endregion
|
|
42
|
+
export { MerklReward, MerklRewardsSdk, toMerklRewards };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "16.0.0-next.
|
|
3
|
+
"version": "16.0.0-next.55",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -107,7 +107,6 @@
|
|
|
107
107
|
"@commitlint/cli": "^21.2.1",
|
|
108
108
|
"@commitlint/config-conventional": "^21.2.0",
|
|
109
109
|
"@gearbox-protocol/biome-config": "^1.1.6",
|
|
110
|
-
"axios": "^1.19.0",
|
|
111
110
|
"husky": "^9.1.7",
|
|
112
111
|
"lint-staged": "^17.3.0",
|
|
113
112
|
"pino": "^10.3.1",
|
|
@@ -122,7 +121,6 @@
|
|
|
122
121
|
"yaml": "^2.9.0"
|
|
123
122
|
},
|
|
124
123
|
"peerDependencies": {
|
|
125
|
-
"axios": "^1.0.0",
|
|
126
124
|
"viem-deal": "^2.0.4"
|
|
127
125
|
},
|
|
128
126
|
"peerDependenciesMeta": {
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
//#endregion
|
|
23
|
-
exports.__toESM = __toESM;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
3
|
-
const require_onchain_utils_bigint_math = require("../../onchain/utils/bigint-math.js");
|
|
4
|
-
const require_onchain_chain_chains = require("../../onchain/chain/chains.js");
|
|
5
|
-
const require_onchain_constants_math = require("../../onchain/constants/math.js");
|
|
6
|
-
const require_onchain_utils_formatter = require("../../onchain/utils/formatter.js");
|
|
7
|
-
require("../../onchain/index.js");
|
|
8
|
-
let axios = require("axios");
|
|
9
|
-
axios = require_runtime.__toESM(axios);
|
|
10
|
-
//#region src/rewards/rewards/extra-apy.ts
|
|
11
|
-
function getKeyForPoolPointsInfo(i) {
|
|
12
|
-
return [
|
|
13
|
-
i.pool,
|
|
14
|
-
i.token,
|
|
15
|
-
i.symbol,
|
|
16
|
-
i.duration,
|
|
17
|
-
i.name,
|
|
18
|
-
i.type,
|
|
19
|
-
i.estimation,
|
|
20
|
-
i.condition
|
|
21
|
-
].join("-");
|
|
22
|
-
}
|
|
23
|
-
var PoolPointsAPI = class PoolPointsAPI {
|
|
24
|
-
constructor() {}
|
|
25
|
-
static defaultBackendUrl = "https://api.gearbox.foundation";
|
|
26
|
-
static async getTotalTokensOnProtocol({ tokensToCheck, tokensList, network, backendUrl = PoolPointsAPI.defaultBackendUrl }) {
|
|
27
|
-
const list = [...new Set(tokensToCheck)];
|
|
28
|
-
return (await Promise.allSettled(list.map((t) => PoolPointsAPI.getTokenTotal(t, network, tokensList, backendUrl)))).map((r, i) => [list[i], r]);
|
|
29
|
-
}
|
|
30
|
-
static async getTokenTotal(token, network, tokensList, backendUrl) {
|
|
31
|
-
const url = `${backendUrl}/v1/getBalanceAt?asset=${token}&chainId=${require_onchain_chain_chains.chains[network]?.id}`;
|
|
32
|
-
const balance = (await axios.default.get(url)).data.result.reduce((sum, r) => r.effective_balance + sum, 0);
|
|
33
|
-
const { decimals = 18 } = tokensList[token] || {};
|
|
34
|
-
return {
|
|
35
|
-
token,
|
|
36
|
-
balance: require_onchain_utils_formatter.toBN(String(balance), decimals)
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
static getPointsByPool({ poolRewards, totalTokenBalances, pools, tokensList }) {
|
|
40
|
-
return pools.reduce((acc, p) => {
|
|
41
|
-
const poolAddress = p.pool.pool.address.toLowerCase();
|
|
42
|
-
acc[poolAddress] = (poolRewards[poolAddress] || []).reduce((acc, pointsInfo) => {
|
|
43
|
-
const { addr: tokenAddress } = tokensList.get(pointsInfo.token) || {};
|
|
44
|
-
const tokenBalance = totalTokenBalances[(tokenAddress || "").toLowerCase()];
|
|
45
|
-
const points = PoolPointsAPI.getPoolTokenPoints(tokenBalance, p, tokensList, pointsInfo);
|
|
46
|
-
if (points !== null) acc.push({
|
|
47
|
-
key: getKeyForPoolPointsInfo(pointsInfo),
|
|
48
|
-
info: pointsInfo,
|
|
49
|
-
points
|
|
50
|
-
});
|
|
51
|
-
return acc;
|
|
52
|
-
}, []);
|
|
53
|
-
return acc;
|
|
54
|
-
}, {});
|
|
55
|
-
}
|
|
56
|
-
static getPoolTokenPoints(tokenBalanceInPool, pool, tokensList, pointsInfo) {
|
|
57
|
-
if (pool.pool.pool.expectedLiquidity <= 0) return 0n;
|
|
58
|
-
if (pointsInfo.estimation === "relative" && !tokenBalanceInPool) return null;
|
|
59
|
-
const { decimals = 18 } = tokensList.get(pointsInfo.token) || {};
|
|
60
|
-
const targetFactor = 10n ** BigInt(decimals);
|
|
61
|
-
const defaultPoints = pointsInfo.amount * targetFactor / require_onchain_constants_math.PERCENTAGE_FACTOR;
|
|
62
|
-
if (pointsInfo.estimation === "absolute") return defaultPoints;
|
|
63
|
-
const { decimals: underlyingDecimals = 18 } = tokensList.get(pool.pool.pool.underlying) || {};
|
|
64
|
-
const underlyingFactor = 10n ** BigInt(underlyingDecimals);
|
|
65
|
-
const points = (tokenBalanceInPool?.balance || 0n) * defaultPoints / (pool.pool.pool.expectedLiquidity * targetFactor / underlyingFactor);
|
|
66
|
-
return require_onchain_utils_bigint_math.BigIntMath.min(points, defaultPoints);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
//#endregion
|
|
70
|
-
exports.PoolPointsAPI = PoolPointsAPI;
|
|
71
|
-
exports.getKeyForPoolPointsInfo = getKeyForPoolPointsInfo;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_rewards_rewards_api = require("./api.js");
|
|
3
|
-
const require_rewards_rewards_extra_apy = require("./extra-apy.js");
|
|
4
|
-
exports.PoolPointsAPI = require_rewards_rewards_extra_apy.PoolPointsAPI;
|
|
5
|
-
exports.getKeyForPoolPointsInfo = require_rewards_rewards_extra_apy.getKeyForPoolPointsInfo;
|
|
6
|
-
exports.getMerklRewards = require_rewards_rewards_api.getMerklRewards;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
3
|
-
let axios = require("axios");
|
|
4
|
-
axios = require_runtime.__toESM(axios);
|
|
5
|
-
//#region src/rewards/rewards/merkl-api.ts
|
|
6
|
-
var MerkleXYZApi = class MerkleXYZApi {
|
|
7
|
-
constructor() {}
|
|
8
|
-
static defaultDomain = "https://api.merkl.xyz";
|
|
9
|
-
static angleDomain = "https://api-merkl.angle.money";
|
|
10
|
-
static apiKeyHeader = "X-API-Key";
|
|
11
|
-
static fetchWithFallback = async (getUrl, apiKey) => {
|
|
12
|
-
const headers = apiKey ? { [MerkleXYZApi.apiKeyHeader]: apiKey } : void 0;
|
|
13
|
-
try {
|
|
14
|
-
return await axios.default.get(getUrl(MerkleXYZApi.defaultDomain), { headers });
|
|
15
|
-
} catch {
|
|
16
|
-
return await axios.default.get(getUrl(MerkleXYZApi.angleDomain), { headers });
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
static getUserRewardsUrl = (options) => (domain) => `${domain}/v4/users/${options.params.user}/rewards?chainId=${options.params.chainId}`;
|
|
20
|
-
};
|
|
21
|
-
//#endregion
|
|
22
|
-
exports.MerkleXYZApi = MerkleXYZApi;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { BigIntMath } from "../../onchain/utils/bigint-math.js";
|
|
2
|
-
import { chains } from "../../onchain/chain/chains.js";
|
|
3
|
-
import { PERCENTAGE_FACTOR } from "../../onchain/constants/math.js";
|
|
4
|
-
import { toBN } from "../../onchain/utils/formatter.js";
|
|
5
|
-
import "../../onchain/index.js";
|
|
6
|
-
import axios from "axios";
|
|
7
|
-
//#region src/rewards/rewards/extra-apy.ts
|
|
8
|
-
function getKeyForPoolPointsInfo(i) {
|
|
9
|
-
return [
|
|
10
|
-
i.pool,
|
|
11
|
-
i.token,
|
|
12
|
-
i.symbol,
|
|
13
|
-
i.duration,
|
|
14
|
-
i.name,
|
|
15
|
-
i.type,
|
|
16
|
-
i.estimation,
|
|
17
|
-
i.condition
|
|
18
|
-
].join("-");
|
|
19
|
-
}
|
|
20
|
-
var PoolPointsAPI = class PoolPointsAPI {
|
|
21
|
-
constructor() {}
|
|
22
|
-
static defaultBackendUrl = "https://api.gearbox.foundation";
|
|
23
|
-
static async getTotalTokensOnProtocol({ tokensToCheck, tokensList, network, backendUrl = PoolPointsAPI.defaultBackendUrl }) {
|
|
24
|
-
const list = [...new Set(tokensToCheck)];
|
|
25
|
-
return (await Promise.allSettled(list.map((t) => PoolPointsAPI.getTokenTotal(t, network, tokensList, backendUrl)))).map((r, i) => [list[i], r]);
|
|
26
|
-
}
|
|
27
|
-
static async getTokenTotal(token, network, tokensList, backendUrl) {
|
|
28
|
-
const url = `${backendUrl}/v1/getBalanceAt?asset=${token}&chainId=${chains[network]?.id}`;
|
|
29
|
-
const balance = (await axios.get(url)).data.result.reduce((sum, r) => r.effective_balance + sum, 0);
|
|
30
|
-
const { decimals = 18 } = tokensList[token] || {};
|
|
31
|
-
return {
|
|
32
|
-
token,
|
|
33
|
-
balance: toBN(String(balance), decimals)
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
static getPointsByPool({ poolRewards, totalTokenBalances, pools, tokensList }) {
|
|
37
|
-
return pools.reduce((acc, p) => {
|
|
38
|
-
const poolAddress = p.pool.pool.address.toLowerCase();
|
|
39
|
-
acc[poolAddress] = (poolRewards[poolAddress] || []).reduce((acc, pointsInfo) => {
|
|
40
|
-
const { addr: tokenAddress } = tokensList.get(pointsInfo.token) || {};
|
|
41
|
-
const tokenBalance = totalTokenBalances[(tokenAddress || "").toLowerCase()];
|
|
42
|
-
const points = PoolPointsAPI.getPoolTokenPoints(tokenBalance, p, tokensList, pointsInfo);
|
|
43
|
-
if (points !== null) acc.push({
|
|
44
|
-
key: getKeyForPoolPointsInfo(pointsInfo),
|
|
45
|
-
info: pointsInfo,
|
|
46
|
-
points
|
|
47
|
-
});
|
|
48
|
-
return acc;
|
|
49
|
-
}, []);
|
|
50
|
-
return acc;
|
|
51
|
-
}, {});
|
|
52
|
-
}
|
|
53
|
-
static getPoolTokenPoints(tokenBalanceInPool, pool, tokensList, pointsInfo) {
|
|
54
|
-
if (pool.pool.pool.expectedLiquidity <= 0) return 0n;
|
|
55
|
-
if (pointsInfo.estimation === "relative" && !tokenBalanceInPool) return null;
|
|
56
|
-
const { decimals = 18 } = tokensList.get(pointsInfo.token) || {};
|
|
57
|
-
const targetFactor = 10n ** BigInt(decimals);
|
|
58
|
-
const defaultPoints = pointsInfo.amount * targetFactor / PERCENTAGE_FACTOR;
|
|
59
|
-
if (pointsInfo.estimation === "absolute") return defaultPoints;
|
|
60
|
-
const { decimals: underlyingDecimals = 18 } = tokensList.get(pool.pool.pool.underlying) || {};
|
|
61
|
-
const underlyingFactor = 10n ** BigInt(underlyingDecimals);
|
|
62
|
-
const points = (tokenBalanceInPool?.balance || 0n) * defaultPoints / (pool.pool.pool.expectedLiquidity * targetFactor / underlyingFactor);
|
|
63
|
-
return BigIntMath.min(points, defaultPoints);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
//#endregion
|
|
67
|
-
export { PoolPointsAPI, getKeyForPoolPointsInfo };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
//#region src/rewards/rewards/merkl-api.ts
|
|
3
|
-
var MerkleXYZApi = class MerkleXYZApi {
|
|
4
|
-
constructor() {}
|
|
5
|
-
static defaultDomain = "https://api.merkl.xyz";
|
|
6
|
-
static angleDomain = "https://api-merkl.angle.money";
|
|
7
|
-
static apiKeyHeader = "X-API-Key";
|
|
8
|
-
static fetchWithFallback = async (getUrl, apiKey) => {
|
|
9
|
-
const headers = apiKey ? { [MerkleXYZApi.apiKeyHeader]: apiKey } : void 0;
|
|
10
|
-
try {
|
|
11
|
-
return await axios.get(getUrl(MerkleXYZApi.defaultDomain), { headers });
|
|
12
|
-
} catch {
|
|
13
|
-
return await axios.get(getUrl(MerkleXYZApi.angleDomain), { headers });
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
static getUserRewardsUrl = (options) => (domain) => `${domain}/v4/users/${options.params.user}/rewards?chainId=${options.params.chainId}`;
|
|
17
|
-
};
|
|
18
|
-
//#endregion
|
|
19
|
-
export { MerkleXYZApi };
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { Apy, ApyDetails, DebtReward, ExternalApy, ExtraCollateralAPY, ExtraCollateralPointsInfo, FarmInfo, GearAPY, GearAPYDetails, PointsInfo, PointsReward, PoolExtraApy, PoolOutputDetails, PoolPointsInfo, TokenOutputDetails } from "./output-details.js";
|
|
2
|
-
import { DataResult, Output } from "./output.js";
|
|
3
|
-
export { Apy, ApyDetails, DataResult, DebtReward, ExternalApy, ExtraCollateralAPY, ExtraCollateralPointsInfo, FarmInfo, GearAPY, GearAPYDetails, Output, PointsInfo, PointsReward, PoolExtraApy, PoolOutputDetails, PoolPointsInfo, TokenOutputDetails };
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { Address } from "viem";
|
|
2
|
-
//#region src/rewards/apy/output-details.d.ts
|
|
3
|
-
interface GearAPY {
|
|
4
|
-
base: number;
|
|
5
|
-
crv: number;
|
|
6
|
-
gear: number;
|
|
7
|
-
gearPrice: number;
|
|
8
|
-
}
|
|
9
|
-
type GearAPYDetails = GearAPY & {
|
|
10
|
-
lastUpdated: string;
|
|
11
|
-
};
|
|
12
|
-
interface TokenOutputDetails<T extends string> {
|
|
13
|
-
chainId: number;
|
|
14
|
-
address: string;
|
|
15
|
-
symbol: string;
|
|
16
|
-
rewards: {
|
|
17
|
-
apy: Array<Omit<ApyDetails, "symbol" | "address">>;
|
|
18
|
-
points: Array<Omit<PointsInfo<T>, "symbol" | "address">>;
|
|
19
|
-
extraRewards: Array<Omit<FarmInfo, "symbol" | "address">>;
|
|
20
|
-
extraCollateralAPY: Array<Omit<ExtraCollateralAPY, "symbol" | "address">>;
|
|
21
|
-
extraCollateralPoints: Array<Omit<ExtraCollateralPointsInfo<T>, "symbol" | "address">>;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
type ApyDetails = Apy & {
|
|
25
|
-
lastUpdated: string;
|
|
26
|
-
};
|
|
27
|
-
interface FarmInfo {
|
|
28
|
-
address: Address;
|
|
29
|
-
symbol: string;
|
|
30
|
-
rewardToken: Address;
|
|
31
|
-
rewardSymbol: string;
|
|
32
|
-
duration: bigint;
|
|
33
|
-
finished: bigint;
|
|
34
|
-
reward: bigint;
|
|
35
|
-
balance: bigint;
|
|
36
|
-
}
|
|
37
|
-
interface Apy {
|
|
38
|
-
address: Address;
|
|
39
|
-
symbol: string;
|
|
40
|
-
protocol: string;
|
|
41
|
-
value: number;
|
|
42
|
-
}
|
|
43
|
-
interface ExtraCollateralAPY extends Omit<Apy, "protocol"> {
|
|
44
|
-
pool: Address;
|
|
45
|
-
type: "relative" | "absolute";
|
|
46
|
-
}
|
|
47
|
-
interface PointsReward<T extends string> {
|
|
48
|
-
name: string;
|
|
49
|
-
units: string;
|
|
50
|
-
multiplier: bigint | "soon";
|
|
51
|
-
type: T;
|
|
52
|
-
}
|
|
53
|
-
interface DebtReward<T extends string> extends PointsReward<T> {
|
|
54
|
-
cm: Address | "any";
|
|
55
|
-
}
|
|
56
|
-
interface PointsInfo<T extends string> {
|
|
57
|
-
symbol: string;
|
|
58
|
-
address: Address;
|
|
59
|
-
rewards: Array<PointsReward<T>>;
|
|
60
|
-
debtRewards?: Array<DebtReward<T>>;
|
|
61
|
-
}
|
|
62
|
-
interface ExtraCollateralPointsInfo<T extends string> extends PointsInfo<T> {
|
|
63
|
-
pool: Address;
|
|
64
|
-
}
|
|
65
|
-
interface PoolOutputDetails<T extends string> {
|
|
66
|
-
chainId: number;
|
|
67
|
-
pool: Address;
|
|
68
|
-
rewards: {
|
|
69
|
-
points: Array<Omit<PoolPointsInfo<T>, "pool">>;
|
|
70
|
-
externalAPY: Array<Omit<ExternalApy, "pool">>;
|
|
71
|
-
extraAPY: Array<Omit<PoolExtraApy, "pool">>;
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
interface PoolPointsInfo<T extends string> {
|
|
75
|
-
pool: Address;
|
|
76
|
-
token: Address;
|
|
77
|
-
symbol: string;
|
|
78
|
-
amount: bigint;
|
|
79
|
-
duration: string | undefined;
|
|
80
|
-
name: string;
|
|
81
|
-
type: T;
|
|
82
|
-
estimation: "absolute" | "relative";
|
|
83
|
-
condition: "deposit" | "cross-chain-deposit" | "holding";
|
|
84
|
-
}
|
|
85
|
-
interface ExternalApy {
|
|
86
|
-
value: number;
|
|
87
|
-
name: string;
|
|
88
|
-
pool: Address;
|
|
89
|
-
}
|
|
90
|
-
interface PoolExtraApy {
|
|
91
|
-
token: Address;
|
|
92
|
-
apy: number;
|
|
93
|
-
rewardToken: Address;
|
|
94
|
-
rewardTokenSymbol: string;
|
|
95
|
-
endTimestamp?: number;
|
|
96
|
-
lastUpdated: string;
|
|
97
|
-
}
|
|
98
|
-
//#endregion
|
|
99
|
-
export { Apy, ApyDetails, DebtReward, ExternalApy, ExtraCollateralAPY, ExtraCollateralPointsInfo, FarmInfo, GearAPY, GearAPYDetails, PointsInfo, PointsReward, PoolExtraApy, PoolOutputDetails, PoolPointsInfo, TokenOutputDetails };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { GearAPYDetails, PoolOutputDetails, TokenOutputDetails } from "./output-details.js";
|
|
2
|
-
//#region src/rewards/apy/output.d.ts
|
|
3
|
-
interface Output<POOL_POINTS_TYPE extends string, TOKEN_POINTS_TYPE extends string> {
|
|
4
|
-
gearApy: DataResult<GearAPYDetails>;
|
|
5
|
-
chains: Record<string, {
|
|
6
|
-
tokens: DataResult<TokenOutputDetails<TOKEN_POINTS_TYPE>[]>;
|
|
7
|
-
pools: DataResult<PoolOutputDetails<POOL_POINTS_TYPE>[]>;
|
|
8
|
-
}>;
|
|
9
|
-
timestamp: string;
|
|
10
|
-
metadata: {
|
|
11
|
-
totalChains: number;
|
|
12
|
-
successfulChains: number;
|
|
13
|
-
failedChains: number;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
type DataResult<T> = {
|
|
17
|
-
status: "ok";
|
|
18
|
-
data: T;
|
|
19
|
-
} | {
|
|
20
|
-
status: "error";
|
|
21
|
-
message: string;
|
|
22
|
-
code?: string;
|
|
23
|
-
};
|
|
24
|
-
//#endregion
|
|
25
|
-
export { DataResult, Output };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { ChainId, Token, TokenAmount } from "../../model/primitives.js";
|
|
2
|
-
import "../../model/index.js";
|
|
3
|
-
import { OnchainSDK } from "../../onchain/OnchainSDK.js";
|
|
4
|
-
import "../../onchain/index.js";
|
|
5
|
-
import { Address } from "viem";
|
|
6
|
-
//#region src/rewards/rewards/api.d.ts
|
|
7
|
-
/**
|
|
8
|
-
* One claimable Merkl liquidity-mining reward, denominated and priced.
|
|
9
|
-
*
|
|
10
|
-
* Both tokens arrive resolved, so a consumer neither looks one up nor
|
|
11
|
-
* reassembles one out of the loose fields Merkl sends.
|
|
12
|
-
*/
|
|
13
|
-
interface MerklReward {
|
|
14
|
-
readonly chainId: ChainId;
|
|
15
|
-
/** Market pool whose depositors the campaign rewards. */
|
|
16
|
-
readonly pool: Address;
|
|
17
|
-
/** That pool's share token — what the campaign is keyed on. */
|
|
18
|
-
readonly poolToken: Token;
|
|
19
|
-
/**
|
|
20
|
-
* The incentive token being handed out, how much of it is claimable
|
|
21
|
-
* (distributed minus already claimed, always > 0) and what that is worth.
|
|
22
|
-
*
|
|
23
|
-
* Priced by Merkl, not by the market oracles: a campaign's incentive token
|
|
24
|
-
* is rarely collateral in the pool it incentivises, so the oracles usually
|
|
25
|
-
* do not know it — GEAR, which most Gearbox campaigns pay in, among them.
|
|
26
|
-
* `valueUsd` is `null` for a token Merkl does not price either.
|
|
27
|
-
*/
|
|
28
|
-
readonly amount: TokenAmount;
|
|
29
|
-
}
|
|
30
|
-
type ReportHandler = (e: unknown, description?: string) => void;
|
|
31
|
-
/**
|
|
32
|
-
* What this read needs off a chain's SDK: which chain to ask Merkl about, the
|
|
33
|
-
* pools a campaign can be keyed on, and the registry that names their tokens.
|
|
34
|
-
*
|
|
35
|
-
* Sliced rather than taking the whole {@link OnchainSDK} so a caller can hand
|
|
36
|
-
* over a narrowed object — a test fixture included — without casting.
|
|
37
|
-
*/
|
|
38
|
-
type MerklRewardsSdk = Pick<OnchainSDK, "chainId" | "marketRegister" | "tokensMeta">;
|
|
39
|
-
interface GetMerklRewardsProps {
|
|
40
|
-
/**
|
|
41
|
-
* The chain's SDK, attached. Reading `marketRegister` before attach throws,
|
|
42
|
-
* which the slice above cannot express.
|
|
43
|
-
*/
|
|
44
|
-
sdk: MerklRewardsSdk;
|
|
45
|
-
account: Address;
|
|
46
|
-
reportError?: ReportHandler;
|
|
47
|
-
/** Raises Merkl's rate limit; the keyless path answers too. */
|
|
48
|
-
apiKey?: string;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* The wallet's claimable Merkl rewards on one chain.
|
|
52
|
-
*
|
|
53
|
-
* Never rejects on a transport failure: the fetch is settled rather than
|
|
54
|
-
* awaited, and a failure goes to `reportError` and yields an empty list. A
|
|
55
|
-
* caller that must tell "this chain is down" from "this chain has no rewards"
|
|
56
|
-
* has to watch that callback.
|
|
57
|
-
*/
|
|
58
|
-
declare function getMerklRewards({ sdk, account, reportError, apiKey }: GetMerklRewardsProps): Promise<MerklReward[]>;
|
|
59
|
-
//#endregion
|
|
60
|
-
export { GetMerklRewardsProps, MerklReward, MerklRewardsSdk, getMerklRewards };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { NetworkType } from "../../onchain/chain/chains.js";
|
|
2
|
-
import { Asset } from "../../onchain/base/types.js";
|
|
3
|
-
import { MarketSuite } from "../../onchain/market/MarketSuite.js";
|
|
4
|
-
import { TokensMeta } from "../../onchain/base/TokensMeta.js";
|
|
5
|
-
import "../../onchain/index.js";
|
|
6
|
-
import { PoolPointsInfo } from "../apy/output-details.js";
|
|
7
|
-
import { TokenData } from "./common.js";
|
|
8
|
-
import { Address } from "viem";
|
|
9
|
-
//#region src/rewards/rewards/extra-apy.d.ts
|
|
10
|
-
interface GetPointsByPoolProps {
|
|
11
|
-
poolRewards: Record<Address, Array<PoolPointsInfo<string>>>;
|
|
12
|
-
totalTokenBalances: Record<Address, Asset>;
|
|
13
|
-
pools: MarketSuite[];
|
|
14
|
-
tokensList: TokensMeta;
|
|
15
|
-
}
|
|
16
|
-
interface GetTotalTokensOnProtocolProps {
|
|
17
|
-
tokensToCheck: Array<Address>;
|
|
18
|
-
tokensList: Record<Address, TokenData>;
|
|
19
|
-
network: NetworkType;
|
|
20
|
-
backendUrl?: string;
|
|
21
|
-
}
|
|
22
|
-
type PoolPointsBase = Record<Address, Array<{
|
|
23
|
-
key: string;
|
|
24
|
-
info: PoolPointsInfo<string>;
|
|
25
|
-
points: bigint;
|
|
26
|
-
}>>;
|
|
27
|
-
declare function getKeyForPoolPointsInfo(i: PoolPointsInfo<string>): string;
|
|
28
|
-
declare class PoolPointsAPI {
|
|
29
|
-
private constructor();
|
|
30
|
-
private static defaultBackendUrl;
|
|
31
|
-
static getTotalTokensOnProtocol({ tokensToCheck, tokensList, network, backendUrl }: GetTotalTokensOnProtocolProps): Promise<[`0x${string}`, PromiseSettledResult<Asset>][]>;
|
|
32
|
-
private static getTokenTotal;
|
|
33
|
-
static getPointsByPool({ poolRewards, totalTokenBalances, pools, tokensList }: GetPointsByPoolProps): PoolPointsBase;
|
|
34
|
-
private static getPoolTokenPoints;
|
|
35
|
-
}
|
|
36
|
-
//#endregion
|
|
37
|
-
export { GetPointsByPoolProps, GetTotalTokensOnProtocolProps, PoolPointsAPI, PoolPointsBase, getKeyForPoolPointsInfo };
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { GetMerklRewardsProps, MerklReward, MerklRewardsSdk, getMerklRewards } from "./api.js";
|
|
2
|
-
import { GetPointsByPoolProps, GetTotalTokensOnProtocolProps, PoolPointsAPI, PoolPointsBase, getKeyForPoolPointsInfo } from "./extra-apy.js";
|
|
3
|
-
export { GetMerklRewardsProps, GetPointsByPoolProps, GetTotalTokensOnProtocolProps, MerklReward, MerklRewardsSdk, PoolPointsAPI, PoolPointsBase, getKeyForPoolPointsInfo, getMerklRewards };
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Address } from "viem";
|
|
2
|
-
//#region src/rewards/rewards/merkl-api.d.ts
|
|
3
|
-
interface UserOptions {
|
|
4
|
-
params: {
|
|
5
|
-
user: string;
|
|
6
|
-
chainId: number;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
interface MerkleXYZUserRewardsV4 {
|
|
10
|
-
chain: MerkleXYZChain;
|
|
11
|
-
rewards: Array<{
|
|
12
|
-
root: Address;
|
|
13
|
-
recipient: Address;
|
|
14
|
-
amount: string;
|
|
15
|
-
claimed: string;
|
|
16
|
-
pending: string;
|
|
17
|
-
proofs: Array<Address>;
|
|
18
|
-
token: {
|
|
19
|
-
address: Address;
|
|
20
|
-
chainId: number;
|
|
21
|
-
symbol: string;
|
|
22
|
-
decimals: number;
|
|
23
|
-
/**
|
|
24
|
-
* USD price of one whole token. Optional because Merkl omits the key
|
|
25
|
-
* outright for the tokens it does not price — points and the like —
|
|
26
|
-
* rather than sending a null.
|
|
27
|
-
*/
|
|
28
|
-
price?: number;
|
|
29
|
-
};
|
|
30
|
-
breakdowns: Array<{
|
|
31
|
-
reason: string;
|
|
32
|
-
amount: string;
|
|
33
|
-
claimed: string;
|
|
34
|
-
pending: string;
|
|
35
|
-
campaignId: Address;
|
|
36
|
-
}>;
|
|
37
|
-
}>;
|
|
38
|
-
}
|
|
39
|
-
type MerkleXYZUserRewardsV4Response = Array<MerkleXYZUserRewardsV4>;
|
|
40
|
-
interface MerkleXYZChain {
|
|
41
|
-
id: number;
|
|
42
|
-
name: string;
|
|
43
|
-
icon: string;
|
|
44
|
-
}
|
|
45
|
-
declare class MerkleXYZApi {
|
|
46
|
-
private constructor();
|
|
47
|
-
static defaultDomain: string;
|
|
48
|
-
static angleDomain: string;
|
|
49
|
-
static apiKeyHeader: string;
|
|
50
|
-
static fetchWithFallback: <T>(getUrl: (domain: string) => string, apiKey?: string) => Promise<import("axios").AxiosResponse<T, any, {}, any>>;
|
|
51
|
-
static getUserRewardsUrl: (options: UserOptions) => (domain: string) => string;
|
|
52
|
-
}
|
|
53
|
-
//#endregion
|
|
54
|
-
export { MerkleXYZApi, MerkleXYZUserRewardsV4, MerkleXYZUserRewardsV4Response };
|