@ichidao/ichi-vaults-sdk 0.1.43 → 2.0.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/README.md +62 -208
- package/dist/abis/types/AlgebraIntegralPool.d.ts +702 -793
- package/dist/abis/types/AlgebraPool.d.ts +693 -730
- package/dist/abis/types/ClPool.d.ts +789 -871
- package/dist/abis/types/DepositGuard.d.ts +193 -178
- package/dist/abis/types/DepositGuardWithHtsWrapping.d.ts +300 -297
- package/dist/abis/types/ERC20.d.ts +120 -147
- package/dist/abis/types/ERC20Wrapper.d.ts +147 -155
- package/dist/abis/types/IchiVault.d.ts +598 -728
- package/dist/abis/types/MultiFeeDistributer.d.ts +314 -423
- package/dist/abis/types/Multicall.d.ts +58 -73
- package/dist/abis/types/UniswapV3Pool.d.ts +654 -693
- package/dist/abis/types/common.d.ts +40 -12
- package/dist/abis/types/factories/AlgebraIntegralPool__factory.d.ts +2 -3
- package/dist/abis/types/factories/AlgebraIntegralPool__factory.js +10 -13
- package/dist/abis/types/factories/AlgebraIntegralPool__factory.js.map +1 -1
- package/dist/abis/types/factories/AlgebraPool__factory.d.ts +2 -3
- package/dist/abis/types/factories/AlgebraPool__factory.js +10 -13
- package/dist/abis/types/factories/AlgebraPool__factory.js.map +1 -1
- package/dist/abis/types/factories/ClPool__factory.d.ts +2 -3
- package/dist/abis/types/factories/ClPool__factory.js +10 -13
- package/dist/abis/types/factories/ClPool__factory.js.map +1 -1
- package/dist/abis/types/factories/DepositGuardWithHtsWrapping__factory.d.ts +2 -3
- package/dist/abis/types/factories/DepositGuardWithHtsWrapping__factory.js +10 -13
- package/dist/abis/types/factories/DepositGuardWithHtsWrapping__factory.js.map +1 -1
- package/dist/abis/types/factories/DepositGuard__factory.d.ts +2 -3
- package/dist/abis/types/factories/DepositGuard__factory.js +10 -13
- package/dist/abis/types/factories/DepositGuard__factory.js.map +1 -1
- package/dist/abis/types/factories/ERC20Wrapper__factory.d.ts +2 -3
- package/dist/abis/types/factories/ERC20Wrapper__factory.js +10 -13
- package/dist/abis/types/factories/ERC20Wrapper__factory.js.map +1 -1
- package/dist/abis/types/factories/ERC20__factory.d.ts +2 -3
- package/dist/abis/types/factories/ERC20__factory.js +10 -13
- package/dist/abis/types/factories/ERC20__factory.js.map +1 -1
- package/dist/abis/types/factories/IchiVault__factory.d.ts +2 -3
- package/dist/abis/types/factories/IchiVault__factory.js +10 -13
- package/dist/abis/types/factories/IchiVault__factory.js.map +1 -1
- package/dist/abis/types/factories/MultiFeeDistributer__factory.d.ts +2 -3
- package/dist/abis/types/factories/MultiFeeDistributer__factory.js +10 -13
- package/dist/abis/types/factories/MultiFeeDistributer__factory.js.map +1 -1
- package/dist/abis/types/factories/Multicall__factory.d.ts +2 -3
- package/dist/abis/types/factories/Multicall__factory.js +10 -13
- package/dist/abis/types/factories/Multicall__factory.js.map +1 -1
- package/dist/abis/types/factories/UniswapV3Pool__factory.d.ts +2 -3
- package/dist/abis/types/factories/UniswapV3Pool__factory.js +10 -13
- package/dist/abis/types/factories/UniswapV3Pool__factory.js.map +1 -1
- package/dist/src/__tests__/index.test.js +356 -738
- package/dist/src/__tests__/index.test.js.map +1 -1
- package/dist/src/abis/types/AlgebraIntegralPool.d.ts +702 -793
- package/dist/src/abis/types/AlgebraPool.d.ts +693 -730
- package/dist/src/abis/types/ClPool.d.ts +789 -871
- package/dist/src/abis/types/DepositGuard.d.ts +193 -178
- package/dist/src/abis/types/DepositGuardWithHtsWrapping.d.ts +300 -297
- package/dist/src/abis/types/ERC20.d.ts +120 -147
- package/dist/src/abis/types/ERC20Wrapper.d.ts +147 -155
- package/dist/src/abis/types/IchiVault.d.ts +598 -728
- package/dist/src/abis/types/MultiFeeDistributer.d.ts +314 -423
- package/dist/src/abis/types/Multicall.d.ts +58 -73
- package/dist/src/abis/types/UniswapV3Pool.d.ts +654 -693
- package/dist/src/abis/types/common.d.ts +40 -12
- package/dist/src/abis/types/factories/AlgebraIntegralPool__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/AlgebraPool__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/ClPool__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/DepositGuardWithHtsWrapping__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/DepositGuard__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/ERC20Wrapper__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/ERC20__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/IchiVault__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/MultiFeeDistributer__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/Multicall__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/UniswapV3Pool__factory.d.ts +2 -3
- package/dist/src/contracts/index.d.ts +1 -1
- package/dist/src/contracts/index.js +12 -12
- package/dist/src/contracts/index.js.map +1 -1
- package/dist/src/functions/_totalBalances.d.ts +2 -3
- package/dist/src/functions/_totalBalances.js +46 -117
- package/dist/src/functions/_totalBalances.js.map +1 -1
- package/dist/src/functions/_vaultEvents.js +347 -488
- package/dist/src/functions/_vaultEvents.js.map +1 -1
- package/dist/src/functions/_withdrawHelpers.d.ts +2 -3
- package/dist/src/functions/_withdrawHelpers.js +13 -62
- package/dist/src/functions/_withdrawHelpers.js.map +1 -1
- package/dist/src/functions/calculateApr.d.ts +1 -1
- package/dist/src/functions/calculateApr.js +77 -150
- package/dist/src/functions/calculateApr.js.map +1 -1
- package/dist/src/functions/calculateDtr.d.ts +1 -1
- package/dist/src/functions/calculateDtr.js +84 -169
- package/dist/src/functions/calculateDtr.js.map +1 -1
- package/dist/src/functions/calculateFees.d.ts +1 -1
- package/dist/src/functions/calculateFees.js +97 -172
- package/dist/src/functions/calculateFees.js.map +1 -1
- package/dist/src/functions/chains.js +6 -6
- package/dist/src/functions/chains.js.map +1 -1
- package/dist/src/functions/claimRewards.d.ts +3 -4
- package/dist/src/functions/claimRewards.js +29 -92
- package/dist/src/functions/claimRewards.js.map +1 -1
- package/dist/src/functions/deposit.d.ts +7 -9
- package/dist/src/functions/deposit.js +199 -364
- package/dist/src/functions/deposit.js.map +1 -1
- package/dist/src/functions/depositWithHtsWrapping.d.ts +4 -6
- package/dist/src/functions/depositWithHtsWrapping.js +109 -226
- package/dist/src/functions/depositWithHtsWrapping.js.map +1 -1
- package/dist/src/functions/getFeeAprs.d.ts +1 -1
- package/dist/src/functions/getFeeAprs.js +55 -111
- package/dist/src/functions/getFeeAprs.js.map +1 -1
- package/dist/src/functions/priceFromPool.d.ts +3 -4
- package/dist/src/functions/priceFromPool.js +99 -208
- package/dist/src/functions/priceFromPool.js.map +1 -1
- package/dist/src/functions/rewardInfo.js +79 -159
- package/dist/src/functions/rewardInfo.js.map +1 -1
- package/dist/src/functions/totalBalances.d.ts +2 -3
- package/dist/src/functions/totalBalances.js +14 -67
- package/dist/src/functions/totalBalances.js.map +1 -1
- package/dist/src/functions/userBalances.d.ts +2 -3
- package/dist/src/functions/userBalances.js +244 -368
- package/dist/src/functions/userBalances.js.map +1 -1
- package/dist/src/functions/userRewards.d.ts +1 -1
- package/dist/src/functions/userRewards.js +87 -145
- package/dist/src/functions/userRewards.js.map +1 -1
- package/dist/src/functions/vault.d.ts +1 -1
- package/dist/src/functions/vault.js +203 -383
- package/dist/src/functions/vault.js.map +1 -1
- package/dist/src/functions/vaultBasics.js +6 -7
- package/dist/src/functions/vaultBasics.js.map +1 -1
- package/dist/src/functions/vaultMetrics.d.ts +1 -1
- package/dist/src/functions/vaultMetrics.js +111 -189
- package/dist/src/functions/vaultMetrics.js.map +1 -1
- package/dist/src/functions/vaultPositions.d.ts +1 -1
- package/dist/src/functions/vaultPositions.js +69 -134
- package/dist/src/functions/vaultPositions.js.map +1 -1
- package/dist/src/functions/vaultTvl.d.ts +1 -1
- package/dist/src/functions/vaultTvl.js +80 -165
- package/dist/src/functions/vaultTvl.js.map +1 -1
- package/dist/src/functions/withdraw.d.ts +6 -8
- package/dist/src/functions/withdraw.js +165 -295
- package/dist/src/functions/withdraw.js.map +1 -1
- package/dist/src/functions/withdrawWithErc20Wrapping.d.ts +2 -4
- package/dist/src/functions/withdrawWithErc20Wrapping.js +59 -126
- package/dist/src/functions/withdrawWithErc20Wrapping.js.map +1 -1
- package/dist/src/graphql/constants.js +217 -212
- package/dist/src/graphql/constants.js.map +1 -1
- package/dist/src/graphql/functions.js +30 -102
- package/dist/src/graphql/functions.js.map +1 -1
- package/dist/src/graphql/queries.js +407 -42
- package/dist/src/graphql/queries.js.map +1 -1
- package/dist/src/index.cjs.js +2 -2
- package/dist/src/index.esm.js +2 -2
- package/dist/src/src/contracts/index.d.ts +1 -1
- package/dist/src/src/functions/_totalBalances.d.ts +2 -3
- package/dist/src/src/functions/_withdrawHelpers.d.ts +2 -3
- package/dist/src/src/functions/calculateApr.d.ts +1 -1
- package/dist/src/src/functions/calculateDtr.d.ts +1 -1
- package/dist/src/src/functions/calculateFees.d.ts +1 -1
- package/dist/src/src/functions/claimRewards.d.ts +3 -4
- package/dist/src/src/functions/deposit.d.ts +7 -9
- package/dist/src/src/functions/depositWithHtsWrapping.d.ts +4 -6
- package/dist/src/src/functions/getFeeAprs.d.ts +1 -1
- package/dist/src/src/functions/priceFromPool.d.ts +3 -4
- package/dist/src/src/functions/totalBalances.d.ts +2 -3
- package/dist/src/src/functions/userBalances.d.ts +2 -3
- package/dist/src/src/functions/userRewards.d.ts +1 -1
- package/dist/src/src/functions/vault.d.ts +1 -1
- package/dist/src/src/functions/vaultMetrics.d.ts +1 -1
- package/dist/src/src/functions/vaultPositions.d.ts +1 -1
- package/dist/src/src/functions/vaultTvl.d.ts +1 -1
- package/dist/src/src/functions/withdraw.d.ts +6 -8
- package/dist/src/src/functions/withdrawWithErc20Wrapping.d.ts +2 -4
- package/dist/src/src/types/calculateGasMargin.d.ts +1 -2
- package/dist/src/src/types/index.d.ts +12 -13
- package/dist/src/src/utils/amountWithSlippage.d.ts +1 -2
- package/dist/src/src/utils/config/addresses.d.ts +1 -1
- package/dist/src/src/utils/formatBigInt.d.ts +1 -2
- package/dist/src/src/utils/getPrice.d.ts +1 -2
- package/dist/src/src/utils/multicallUtils.d.ts +9 -10
- package/dist/src/src/utils/parseBigInt.d.ts +1 -2
- package/dist/src/types/calculateGasMargin.d.ts +1 -2
- package/dist/src/types/calculateGasMargin.js +4 -5
- package/dist/src/types/calculateGasMargin.js.map +1 -1
- package/dist/src/types/index.d.ts +12 -13
- package/dist/src/types/index.js +1 -0
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/utils/amountWithSlippage.d.ts +1 -2
- package/dist/src/utils/amountWithSlippage.js +1 -1
- package/dist/src/utils/amountWithSlippage.js.map +1 -1
- package/dist/src/utils/cache.js +2 -2
- package/dist/src/utils/cache.js.map +1 -1
- package/dist/src/utils/config/addresses.d.ts +1 -1
- package/dist/src/utils/config/addresses.js +276 -268
- package/dist/src/utils/config/addresses.js.map +1 -1
- package/dist/src/utils/formatBigInt.d.ts +1 -2
- package/dist/src/utils/formatBigInt.js +4 -5
- package/dist/src/utils/formatBigInt.js.map +1 -1
- package/dist/src/utils/getConfigByFactory.js +24 -28
- package/dist/src/utils/getConfigByFactory.js.map +1 -1
- package/dist/src/utils/getGraphUrls.js +8 -12
- package/dist/src/utils/getGraphUrls.js.map +1 -1
- package/dist/src/utils/getPrice.d.ts +1 -2
- package/dist/src/utils/getPrice.js +5 -6
- package/dist/src/utils/getPrice.js.map +1 -1
- package/dist/src/utils/isVelodrome.js +2 -3
- package/dist/src/utils/isVelodrome.js.map +1 -1
- package/dist/src/utils/multicallUtils.d.ts +9 -10
- package/dist/src/utils/multicallUtils.js +38 -93
- package/dist/src/utils/multicallUtils.js.map +1 -1
- package/dist/src/utils/parseBigInt.d.ts +1 -2
- package/dist/src/utils/parseBigInt.js +5 -7
- package/dist/src/utils/parseBigInt.js.map +1 -1
- package/dist/src/utils/positionKey.js +2 -4
- package/dist/src/utils/positionKey.js.map +1 -1
- package/package.json +5 -17
|
@@ -2,205 +2,130 @@
|
|
|
2
2
|
/* eslint-disable no-redeclare */
|
|
3
3
|
/* eslint-disable import/prefer-default-export */
|
|
4
4
|
/* eslint-disable import/no-cycle */
|
|
5
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
15
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
16
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
17
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
18
|
-
function step(op) {
|
|
19
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
20
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
21
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
22
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
23
|
-
switch (op[0]) {
|
|
24
|
-
case 0: case 1: t = op; break;
|
|
25
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
26
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
27
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
28
|
-
default:
|
|
29
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
30
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
31
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
32
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
33
|
-
if (t[2]) _.ops.pop();
|
|
34
|
-
_.trys.pop(); continue;
|
|
35
|
-
}
|
|
36
|
-
op = body.call(thisArg, _);
|
|
37
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
38
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
5
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
6
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
7
|
};
|
|
44
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
9
|
exports.getFeesCollectedInfo = exports.getFeesCollected = exports.getTotalFeesAmountInBaseTokens = exports.getFeesAmountInBaseTokens = exports.getTotalAmountsAtFeeCollectionEvent = void 0;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
var _vaultEvents_1 = require("./_vaultEvents");
|
|
10
|
+
const vault_1 = require("./vault");
|
|
11
|
+
const _totalBalances_1 = require("./_totalBalances");
|
|
12
|
+
const formatBigInt_1 = __importDefault(require("../utils/formatBigInt"));
|
|
13
|
+
const timestamps_1 = require("../utils/timestamps");
|
|
14
|
+
const deposit_1 = require("./deposit");
|
|
15
|
+
const getPrice_1 = __importDefault(require("../utils/getPrice"));
|
|
16
|
+
const priceFromPool_1 = require("./priceFromPool");
|
|
17
|
+
const getGraphUrls_1 = require("../utils/getGraphUrls");
|
|
18
|
+
const _vaultEvents_1 = require("./_vaultEvents");
|
|
56
19
|
function getCollectedTokenAmountBN(ind, feesDataset) {
|
|
57
|
-
|
|
58
|
-
? feesDataset.map(
|
|
59
|
-
: feesDataset.map(
|
|
60
|
-
|
|
20
|
+
const amounts = ind === 0
|
|
21
|
+
? feesDataset.map((r) => BigInt(r.feeAmount0))
|
|
22
|
+
: feesDataset.map((r) => BigInt(r.feeAmount1));
|
|
23
|
+
const amountBN = amounts.reduce((total, curr) => total + curr, 0n);
|
|
61
24
|
return amountBN;
|
|
62
25
|
}
|
|
63
26
|
function getTotalAmountsAtFeeCollectionEvent(objFees, isVaultInverted, token0Decimals, token1Decimals) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
27
|
+
const depositTokenDecimals = isVaultInverted ? token1Decimals : token0Decimals;
|
|
28
|
+
const scarceTokenDecimals = isVaultInverted ? token0Decimals : token1Decimals;
|
|
29
|
+
const price0 = !isVaultInverted
|
|
67
30
|
? 1
|
|
68
|
-
: (0, getPrice_1.default)(isVaultInverted,
|
|
69
|
-
|
|
31
|
+
: (0, getPrice_1.default)(isVaultInverted, BigInt(objFees.sqrtPrice), depositTokenDecimals, scarceTokenDecimals, 15);
|
|
32
|
+
const price1 = isVaultInverted
|
|
70
33
|
? 1
|
|
71
|
-
: (0, getPrice_1.default)(isVaultInverted,
|
|
72
|
-
|
|
73
|
-
|
|
34
|
+
: (0, getPrice_1.default)(isVaultInverted, BigInt(objFees.sqrtPrice), depositTokenDecimals, scarceTokenDecimals, 15);
|
|
35
|
+
const amount0 = Number((0, formatBigInt_1.default)(BigInt(objFees.totalAmount0), token0Decimals)) * price0;
|
|
36
|
+
const amount1 = Number((0, formatBigInt_1.default)(BigInt(objFees.totalAmount1), token1Decimals)) * price1;
|
|
74
37
|
return [amount0, amount1];
|
|
75
38
|
}
|
|
76
39
|
exports.getTotalAmountsAtFeeCollectionEvent = getTotalAmountsAtFeeCollectionEvent;
|
|
77
40
|
function getFeesAmountInBaseTokens(objFees, isVaultInverted, token0Decimals, token1Decimals) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
41
|
+
const depositTokenDecimals = isVaultInverted ? token1Decimals : token0Decimals;
|
|
42
|
+
const scarceTokenDecimals = isVaultInverted ? token0Decimals : token1Decimals;
|
|
43
|
+
const price0 = !isVaultInverted
|
|
81
44
|
? 1
|
|
82
|
-
: (0, getPrice_1.default)(isVaultInverted,
|
|
83
|
-
|
|
45
|
+
: (0, getPrice_1.default)(isVaultInverted, BigInt(objFees.sqrtPrice), depositTokenDecimals, scarceTokenDecimals, 15);
|
|
46
|
+
const price1 = isVaultInverted
|
|
84
47
|
? 1
|
|
85
|
-
: (0, getPrice_1.default)(isVaultInverted,
|
|
86
|
-
|
|
87
|
-
|
|
48
|
+
: (0, getPrice_1.default)(isVaultInverted, BigInt(objFees.sqrtPrice), depositTokenDecimals, scarceTokenDecimals, 15);
|
|
49
|
+
const amount0 = Number((0, formatBigInt_1.default)(BigInt(objFees.feeAmount0), token0Decimals)) * price0;
|
|
50
|
+
const amount1 = Number((0, formatBigInt_1.default)(BigInt(objFees.feeAmount1), token1Decimals)) * price1;
|
|
88
51
|
return amount0 + amount1;
|
|
89
52
|
}
|
|
90
53
|
exports.getFeesAmountInBaseTokens = getFeesAmountInBaseTokens;
|
|
91
54
|
function getTotalFeesAmountInBaseTokens(feesDataset, t0decimals, t1decimals, isInverted) {
|
|
92
|
-
|
|
55
|
+
const amount = feesDataset.reduce((total, curr) => total + getFeesAmountInBaseTokens(curr, isInverted, t0decimals, t1decimals), 0);
|
|
93
56
|
return amount;
|
|
94
57
|
}
|
|
95
58
|
exports.getTotalFeesAmountInBaseTokens = getTotalFeesAmountInBaseTokens;
|
|
96
|
-
function getFeesCollected(vaultAddress, jsonProvider, dex, rawOrDays, days) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
total1: amount1BN,
|
|
127
|
-
0: amount0BN,
|
|
128
|
-
1: amount1BN,
|
|
129
|
-
};
|
|
130
|
-
if (typeof rawOrDays !== 'boolean') {
|
|
131
|
-
feeAmounts = {
|
|
132
|
-
total0: (0, formatBigInt_1.default)(feeAmountsBN.total0, token0Decimals),
|
|
133
|
-
total1: (0, formatBigInt_1.default)(feeAmountsBN.total1, token1Decimals),
|
|
134
|
-
0: (0, formatBigInt_1.default)(feeAmountsBN.total0, token0Decimals),
|
|
135
|
-
1: (0, formatBigInt_1.default)(feeAmountsBN.total1, token1Decimals),
|
|
136
|
-
};
|
|
137
|
-
return [2 /*return*/, feeAmounts];
|
|
138
|
-
}
|
|
139
|
-
return [2 /*return*/, feeAmountsBN];
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
});
|
|
59
|
+
async function getFeesCollected(vaultAddress, jsonProvider, dex, rawOrDays, days) {
|
|
60
|
+
const { chainId, vault } = await (0, vault_1.validateVaultData)(vaultAddress, jsonProvider, dex);
|
|
61
|
+
(0, getGraphUrls_1.getGraphUrls)(chainId, dex, true);
|
|
62
|
+
const token0Decimals = await (0, _totalBalances_1.getTokenDecimals)(vault.tokenA, jsonProvider, chainId);
|
|
63
|
+
const token1Decimals = await (0, _totalBalances_1.getTokenDecimals)(vault.tokenB, jsonProvider, chainId);
|
|
64
|
+
const numOfDays = typeof rawOrDays === 'boolean' ? days : rawOrDays;
|
|
65
|
+
const rebalances = await (0, _vaultEvents_1._getRebalances)(vaultAddress, chainId, dex, numOfDays);
|
|
66
|
+
if (!rebalances)
|
|
67
|
+
throw new Error(`Error getting vault rebalances on ${chainId} for ${vaultAddress}`);
|
|
68
|
+
const collectedFees = await (0, _vaultEvents_1._getFeesCollectedEvents)(vaultAddress, chainId, dex, numOfDays);
|
|
69
|
+
if (!collectedFees)
|
|
70
|
+
throw new Error(`Error getting vault collected fees on ${chainId} for ${vaultAddress}`);
|
|
71
|
+
const amount0BN = getCollectedTokenAmountBN(0, rebalances) + getCollectedTokenAmountBN(0, collectedFees);
|
|
72
|
+
const amount1BN = getCollectedTokenAmountBN(1, rebalances) + getCollectedTokenAmountBN(1, collectedFees);
|
|
73
|
+
const feeAmountsBN = {
|
|
74
|
+
total0: amount0BN,
|
|
75
|
+
total1: amount1BN,
|
|
76
|
+
0: amount0BN,
|
|
77
|
+
1: amount1BN,
|
|
78
|
+
};
|
|
79
|
+
if (typeof rawOrDays !== 'boolean') {
|
|
80
|
+
const feeAmounts = {
|
|
81
|
+
total0: (0, formatBigInt_1.default)(feeAmountsBN.total0, token0Decimals),
|
|
82
|
+
total1: (0, formatBigInt_1.default)(feeAmountsBN.total1, token1Decimals),
|
|
83
|
+
0: (0, formatBigInt_1.default)(feeAmountsBN.total0, token0Decimals),
|
|
84
|
+
1: (0, formatBigInt_1.default)(feeAmountsBN.total1, token1Decimals),
|
|
85
|
+
};
|
|
86
|
+
return feeAmounts;
|
|
87
|
+
}
|
|
88
|
+
return feeAmountsBN;
|
|
143
89
|
}
|
|
144
90
|
exports.getFeesCollected = getFeesCollected;
|
|
145
|
-
function getFeesCollectedInfo(vaultAddress, jsonProvider, dex, forDays) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
var arrRebalances = rebalances
|
|
182
|
-
.slice()
|
|
183
|
-
.filter(function (r) { return Number(r.createdAtTimestamp) * 1000 > Date.now() - (0, timestamps_1.daysToMilliseconds)(dayPeriod); });
|
|
184
|
-
var arrOtherFees = collectedFees
|
|
185
|
-
.slice()
|
|
186
|
-
.filter(function (r) { return Number(r.createdAtTimestamp) * 1000 > Date.now() - (0, timestamps_1.daysToMilliseconds)(dayPeriod); });
|
|
187
|
-
var amount0BN = getCollectedTokenAmountBN(0, arrRebalances).add(getCollectedTokenAmountBN(0, arrOtherFees));
|
|
188
|
-
var amount1BN = getCollectedTokenAmountBN(1, arrRebalances).add(getCollectedTokenAmountBN(1, arrOtherFees));
|
|
189
|
-
var totalFeesAmount = getTotalFeesAmountInBaseTokens(arrRebalances, token0Decimals, token1Decimals, isVaultInverted) +
|
|
190
|
-
getTotalFeesAmountInBaseTokens(arrOtherFees, token0Decimals, token1Decimals, isVaultInverted);
|
|
191
|
-
var pct = dayPeriod !== 0 && tvl !== 0 ? (((totalFeesAmount / dayPeriod) * 365) / tvl) * 100 : 0;
|
|
192
|
-
var feesCollectedInfo = {
|
|
193
|
-
timePeriod: dayPeriod,
|
|
194
|
-
feeAmount0: (0, formatBigInt_1.default)(amount0BN, token0Decimals),
|
|
195
|
-
feeAmount1: (0, formatBigInt_1.default)(amount1BN, token1Decimals),
|
|
196
|
-
pctAPR: pct,
|
|
197
|
-
};
|
|
198
|
-
result.push(feesCollectedInfo);
|
|
199
|
-
});
|
|
200
|
-
return [2 /*return*/, result];
|
|
201
|
-
}
|
|
202
|
-
});
|
|
91
|
+
async function getFeesCollectedInfo(vaultAddress, jsonProvider, dex, forDays) {
|
|
92
|
+
const { chainId, vault } = await (0, vault_1.validateVaultData)(vaultAddress, jsonProvider, dex);
|
|
93
|
+
(0, getGraphUrls_1.getGraphUrls)(chainId, dex, true);
|
|
94
|
+
const token0Decimals = await (0, _totalBalances_1.getTokenDecimals)(vault.tokenA, jsonProvider, chainId);
|
|
95
|
+
const token1Decimals = await (0, _totalBalances_1.getTokenDecimals)(vault.tokenB, jsonProvider, chainId);
|
|
96
|
+
const isVaultInverted = await (0, deposit_1.isTokenAllowed)(1, vaultAddress, jsonProvider, dex);
|
|
97
|
+
const tvl = await (0, priceFromPool_1.getVaultTvl)(vault, jsonProvider, chainId, dex, isVaultInverted, token0Decimals, token1Decimals);
|
|
98
|
+
const defaultArrayDays = [1, 7, 30];
|
|
99
|
+
const arrayDays = forDays && forDays.length > 0 ? forDays : defaultArrayDays;
|
|
100
|
+
const maxTimePeriod = Math.max(...arrayDays);
|
|
101
|
+
const rebalances = await (0, _vaultEvents_1._getRebalances)(vaultAddress, chainId, dex, maxTimePeriod);
|
|
102
|
+
if (!rebalances)
|
|
103
|
+
throw new Error(`Error getting vault rebalances on ${chainId} for ${vaultAddress}`);
|
|
104
|
+
const collectedFees = await (0, _vaultEvents_1._getFeesCollectedEvents)(vaultAddress, chainId, dex, maxTimePeriod);
|
|
105
|
+
if (!collectedFees)
|
|
106
|
+
throw new Error(`Error getting vault collected fees on ${chainId} for ${vaultAddress}`);
|
|
107
|
+
const result = [];
|
|
108
|
+
arrayDays.forEach((dayPeriod) => {
|
|
109
|
+
const arrRebalances = rebalances
|
|
110
|
+
.slice()
|
|
111
|
+
.filter((r) => Number(r.createdAtTimestamp) * 1000 > Date.now() - (0, timestamps_1.daysToMilliseconds)(dayPeriod));
|
|
112
|
+
const arrOtherFees = collectedFees
|
|
113
|
+
.slice()
|
|
114
|
+
.filter((r) => Number(r.createdAtTimestamp) * 1000 > Date.now() - (0, timestamps_1.daysToMilliseconds)(dayPeriod));
|
|
115
|
+
const amount0BN = getCollectedTokenAmountBN(0, arrRebalances) + getCollectedTokenAmountBN(0, arrOtherFees);
|
|
116
|
+
const amount1BN = getCollectedTokenAmountBN(1, arrRebalances) + getCollectedTokenAmountBN(1, arrOtherFees);
|
|
117
|
+
const totalFeesAmount = getTotalFeesAmountInBaseTokens(arrRebalances, token0Decimals, token1Decimals, isVaultInverted) +
|
|
118
|
+
getTotalFeesAmountInBaseTokens(arrOtherFees, token0Decimals, token1Decimals, isVaultInverted);
|
|
119
|
+
const pct = dayPeriod !== 0 && tvl !== 0 ? (((totalFeesAmount / dayPeriod) * 365) / tvl) * 100 : 0;
|
|
120
|
+
const feesCollectedInfo = {
|
|
121
|
+
timePeriod: dayPeriod,
|
|
122
|
+
feeAmount0: (0, formatBigInt_1.default)(amount0BN, token0Decimals),
|
|
123
|
+
feeAmount1: (0, formatBigInt_1.default)(amount1BN, token1Decimals),
|
|
124
|
+
pctAPR: pct,
|
|
125
|
+
};
|
|
126
|
+
result.push(feesCollectedInfo);
|
|
203
127
|
});
|
|
128
|
+
return result;
|
|
204
129
|
}
|
|
205
130
|
exports.getFeesCollectedInfo = getFeesCollectedInfo;
|
|
206
131
|
//# sourceMappingURL=calculateFees.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculateFees.js","sourceRoot":"","sources":["../../../src/functions/calculateFees.ts"],"names":[],"mappings":";AAAA,iCAAiC;AACjC,iDAAiD;AACjD,oCAAoC
|
|
1
|
+
{"version":3,"file":"calculateFees.js","sourceRoot":"","sources":["../../../src/functions/calculateFees.ts"],"names":[],"mappings":";AAAA,iCAAiC;AACjC,iDAAiD;AACjD,oCAAoC;;;;;;AAIpC,mCAA4C;AAC5C,qDAAoD;AACpD,yEAAiD;AACjD,oDAAyD;AACzD,uCAA2C;AAC3C,iEAAyC;AACzC,mDAA8C;AAC9C,wDAAqD;AACrD,iDAAyE;AAEzE,SAAS,yBAAyB,CAAC,GAAU,EAAE,WAAmB;IAChE,MAAM,OAAO,GACX,GAAG,KAAK,CAAC;QACP,CAAC,CA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@@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getChainsForDex = exports.getSupportedDexes = void 0;
|
|
4
4
|
// eslint-disable-next-line import/no-cycle
|
|
5
|
-
|
|
5
|
+
const addresses_1 = require("../utils/config/addresses");
|
|
6
6
|
function getSupportedDexes(chainId) {
|
|
7
|
-
|
|
7
|
+
const chainConfig = addresses_1.addressConfig[chainId];
|
|
8
8
|
if (!chainConfig) {
|
|
9
|
-
throw new Error(
|
|
9
|
+
throw new Error(`Unsupported chainId: ${chainId}`);
|
|
10
10
|
}
|
|
11
11
|
return Object.keys(chainConfig);
|
|
12
12
|
}
|
|
13
13
|
exports.getSupportedDexes = getSupportedDexes;
|
|
14
14
|
function getChainsForDex(dex) {
|
|
15
|
-
|
|
16
|
-
Object.keys(addresses_1.addressConfig).forEach(
|
|
17
|
-
|
|
15
|
+
const chainsWithDex = [];
|
|
16
|
+
Object.keys(addresses_1.addressConfig).forEach((chainId) => {
|
|
17
|
+
const chainConfig = addresses_1.addressConfig[Number(chainId)];
|
|
18
18
|
// Check if the DEX exists in the current chain configuration
|
|
19
19
|
if (chainConfig && dex in chainConfig) {
|
|
20
20
|
chainsWithDex.push(Number(chainId));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chains.js","sourceRoot":"","sources":["../../../src/functions/chains.ts"],"names":[],"mappings":";;;AAEA,2CAA2C;AAC3C,
|
|
1
|
+
{"version":3,"file":"chains.js","sourceRoot":"","sources":["../../../src/functions/chains.ts"],"names":[],"mappings":";;;AAEA,2CAA2C;AAC3C,yDAA0D;AAE1D,SAAgB,iBAAiB,CAAC,OAAyB;IACzD,MAAM,WAAW,GAAG,yBAAa,CAAC,OAAO,CAAC,CAAC;IAE3C,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,EAAE,CAAC,CAAC;KACpD;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,CAAmB,CAAC;AACpD,CAAC;AARD,8CAQC;AAED,SAAgB,eAAe,CAAC,GAAiB;IAC/C,MAAM,aAAa,GAAuB,EAAE,CAAC;IAE7C,MAAM,CAAC,IAAI,CAAC,yBAAa,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7C,MAAM,WAAW,GAAG,yBAAa,CAAC,MAAM,CAAC,OAAO,CAAqB,CAAC,CAAC;QAEvE,6DAA6D;QAC7D,IAAI,WAAW,IAAI,GAAG,IAAI,WAAW,EAAE;YACrC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAqB,CAAC,CAAC;SACzD;IACH,CAAC,CAAC,CAAC;IACH,OAAO,aAAa,CAAC;AACvB,CAAC;AAZD,0CAYC"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ContractTransaction, Overrides } from 'ethers';
|
|
1
|
+
import { ContractTransactionResponse, Overrides, Signer } from 'ethers';
|
|
3
2
|
import { SupportedDex } from '../types';
|
|
4
3
|
/**
|
|
5
4
|
* Claims rewards from the farming contract associated with a vault
|
|
6
5
|
*
|
|
7
6
|
* @param accountAddress - The address of the account claiming rewards
|
|
8
7
|
* @param vaultAddress - The address of the vault
|
|
9
|
-
* @param
|
|
8
|
+
* @param signer - The signer for the transaction
|
|
10
9
|
* @param dex - The DEX to use
|
|
11
10
|
* @param overrides - Optional transaction overrides
|
|
12
11
|
* @returns The transaction
|
|
13
12
|
*/
|
|
14
|
-
export declare function claimRewards(accountAddress: string, vaultAddress: string,
|
|
13
|
+
export declare function claimRewards(accountAddress: string, vaultAddress: string, signer: Signer, dex: SupportedDex, overrides?: Overrides): Promise<ContractTransactionResponse>;
|
|
@@ -1,109 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
3
|
exports.claimRewards = void 0;
|
|
51
|
-
|
|
4
|
+
const isVelodrome_1 = require("../utils/isVelodrome");
|
|
52
5
|
// eslint-disable-next-line import/no-cycle
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
6
|
+
const vault_1 = require("./vault");
|
|
7
|
+
const contracts_1 = require("../contracts");
|
|
8
|
+
const calculateGasMargin_1 = require("../types/calculateGasMargin");
|
|
56
9
|
/**
|
|
57
10
|
* Claims rewards from the farming contract associated with a vault
|
|
58
11
|
*
|
|
59
12
|
* @param accountAddress - The address of the account claiming rewards
|
|
60
13
|
* @param vaultAddress - The address of the vault
|
|
61
|
-
* @param
|
|
14
|
+
* @param signer - The signer for the transaction
|
|
62
15
|
* @param dex - The DEX to use
|
|
63
16
|
* @param overrides - Optional transaction overrides
|
|
64
17
|
* @returns The transaction
|
|
65
18
|
*/
|
|
66
19
|
// eslint-disable-next-line import/prefer-default-export
|
|
67
|
-
function claimRewards(accountAddress, vaultAddress,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return [3 /*break*/, 5];
|
|
92
|
-
case 3:
|
|
93
|
-
_c = calculateGasMargin_1.calculateGasMargin;
|
|
94
|
-
return [4 /*yield*/, farmingContract.estimateGas.getReward(accountAddress, rewardTokenAddresses)];
|
|
95
|
-
case 4:
|
|
96
|
-
_b = _c.apply(void 0, [_d.sent()]);
|
|
97
|
-
_d.label = 5;
|
|
98
|
-
case 5:
|
|
99
|
-
gasLimit = _b;
|
|
100
|
-
return [4 /*yield*/, farmingContract.getReward(accountAddress, rewardTokenAddresses, __assign(__assign({}, overrides), { gasLimit: gasLimit }))];
|
|
101
|
-
case 6:
|
|
102
|
-
tx = _d.sent();
|
|
103
|
-
return [2 /*return*/, tx];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
20
|
+
async function claimRewards(accountAddress, vaultAddress, signer, dex, overrides) {
|
|
21
|
+
if (!signer.provider) {
|
|
22
|
+
throw new Error('Signer must be connected to a provider');
|
|
23
|
+
}
|
|
24
|
+
const jsonProvider = signer.provider;
|
|
25
|
+
const network = await jsonProvider.getNetwork();
|
|
26
|
+
const chainId = Number(network.chainId);
|
|
27
|
+
const isVelodrome = (0, isVelodrome_1.isVelodromeDex)(chainId, dex);
|
|
28
|
+
if (!isVelodrome) {
|
|
29
|
+
throw new Error(`This function is not supported on chain ${chainId} and dex ${dex}`);
|
|
30
|
+
}
|
|
31
|
+
// Get the vault data to find the farming contract
|
|
32
|
+
const { vault } = await (0, vault_1.validateVaultData)(vaultAddress, jsonProvider, dex);
|
|
33
|
+
if (!vault.farmingContract || !vault.rewardTokens || vault.rewardTokens.length <= 0) {
|
|
34
|
+
throw new Error(`Vault ${vaultAddress} does not have an associated farming contract or reward tokens`);
|
|
35
|
+
}
|
|
36
|
+
const farmingContract = (0, contracts_1.getMultiFeeDistributorContract)(vault.farmingContract, signer);
|
|
37
|
+
const rewardTokenAddresses = vault.rewardTokens.map((t) => t.token);
|
|
38
|
+
// Estimate gas for the transaction
|
|
39
|
+
const gasLimit = overrides?.gasLimit ??
|
|
40
|
+
(0, calculateGasMargin_1.calculateGasMargin)(await farmingContract.getReward.estimateGas(accountAddress, rewardTokenAddresses));
|
|
41
|
+
// Execute the claim transaction
|
|
42
|
+
const tx = await farmingContract.getReward(accountAddress, rewardTokenAddresses, { ...overrides, gasLimit });
|
|
43
|
+
return tx;
|
|
107
44
|
}
|
|
108
45
|
exports.claimRewards = claimRewards;
|
|
109
46
|
//# sourceMappingURL=claimRewards.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claimRewards.js","sourceRoot":"","sources":["../../../src/functions/claimRewards.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"claimRewards.js","sourceRoot":"","sources":["../../../src/functions/claimRewards.ts"],"names":[],"mappings":";;;AAEA,sDAAsD;AACtD,2CAA2C;AAC3C,mCAA4C;AAC5C,4CAA8D;AAC9D,oEAAiE;AAEjE;;;;;;;;;GASG;AACH,wDAAwD;AACjD,KAAK,UAAU,YAAY,CAChC,cAAsB,EACtB,YAAoB,EACpB,MAAc,EACd,GAAiB,EACjB,SAAqB;IAErB,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;KAC3D;IACD,MAAM,YAAY,GAAG,MAAM,CAAC,QAA2B,CAAC;IACxD,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,UAAU,EAAE,CAAC;IAChD,MAAM,OAAO,GAAG,MAAM,CA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JsonRpcProvider, ContractTransactionResponse, Overrides, Signer } from 'ethers';
|
|
4
2
|
import { SupportedDex } from '../types';
|
|
5
3
|
export declare function isTokenAllowed(tokenIdx: 0 | 1, vaultAddress: string, jsonProvider: JsonRpcProvider, dex: SupportedDex): Promise<boolean>;
|
|
6
|
-
export declare function isDepositTokenApproved(accountAddress: string, tokenIdx: 0 | 1, amount: string | number |
|
|
7
|
-
export declare function approveDepositToken(accountAddress: string, tokenIdx: 0 | 1, vaultAddress: string,
|
|
8
|
-
export declare function _getMaxDepositAmount(tokenIdx: 0 | 1, vaultAddress: string, jsonProvider: JsonRpcProvider): Promise<
|
|
9
|
-
export declare function getMaxDepositAmount(tokenIdx: 0 | 1, vaultAddress: string, jsonProvider: JsonRpcProvider, dex: SupportedDex): Promise<
|
|
10
|
-
export declare function deposit(accountAddress: string, amount0: string | number |
|
|
11
|
-
export declare function depositNativeToken(accountAddress: string, amount0: string | number |
|
|
4
|
+
export declare function isDepositTokenApproved(accountAddress: string, tokenIdx: 0 | 1, amount: string | number | bigint, vaultAddress: string, jsonProvider: JsonRpcProvider, dex: SupportedDex): Promise<boolean>;
|
|
5
|
+
export declare function approveDepositToken(accountAddress: string, tokenIdx: 0 | 1, vaultAddress: string, signer: Signer, dex: SupportedDex, amount?: string | number | bigint, overrides?: Overrides): Promise<ContractTransactionResponse>;
|
|
6
|
+
export declare function _getMaxDepositAmount(tokenIdx: 0 | 1, vaultAddress: string, jsonProvider: JsonRpcProvider): Promise<bigint>;
|
|
7
|
+
export declare function getMaxDepositAmount(tokenIdx: 0 | 1, vaultAddress: string, jsonProvider: JsonRpcProvider, dex: SupportedDex): Promise<bigint>;
|
|
8
|
+
export declare function deposit(accountAddress: string, amount0: string | number | bigint, amount1: string | number | bigint, vaultAddress: string, signer: Signer, dex: SupportedDex, percentSlippage?: number, overrides?: Overrides): Promise<ContractTransactionResponse>;
|
|
9
|
+
export declare function depositNativeToken(accountAddress: string, amount0: string | number | bigint, amount1: string | number | bigint, vaultAddress: string, signer: Signer, dex: SupportedDex, percentSlippage?: number, overrides?: Overrides): Promise<ContractTransactionResponse>;
|