@curvefi/api 2.21.2 → 2.21.3

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.
@@ -17,7 +17,7 @@ exports.COINS_FANTOM = (0, utils_1.lowerCaseValues)({
17
17
  'dai+usdc': '0x27e611fd27b276acbd5ffd632e5eaebec9761e40',
18
18
  'frax': '0xdc301622e621166bd8e82f2ca0a26c13ad0be355',
19
19
  // --- BTC ---
20
- 'btc': '0x321162Cd933E2Be498Cd2267a90534A804051b11',
20
+ 'wbtc': '0x321162Cd933E2Be498Cd2267a90534A804051b11',
21
21
  'renbtc': '0xDBf31dF14B66535aF65AaC99C32e9eA844e14501',
22
22
  // --- ETH ---
23
23
  'eth': '0x74b23882a30290451A17c44f4F05243b6b58C76d',
@@ -85,8 +85,8 @@ exports.POOLS_DATA_FANTOM = (0, utils_1.lowerCasePoolDataAddresses)({
85
85
  // old_gauge: '0x6600e98b71dabfD4A8Cac03b302B0189Adb86Afb',
86
86
  // gauge_address: '0xBdFF0C27dd073C119ebcb1299a68A6A92aE607F0',
87
87
  gauge_address: '0xbC38bD19227F91424eD4132F630f51C9A42Fa338',
88
- underlying_coins: ['BTC', 'renBTC'],
89
- wrapped_coins: ['BTC', 'renBTC'],
88
+ underlying_coins: ['WBTC', 'renBTC'],
89
+ wrapped_coins: ['WBTC', 'renBTC'],
90
90
  underlying_coin_addresses: [
91
91
  '0x321162Cd933E2Be498Cd2267a90534A804051b11',
92
92
  '0xDBf31dF14B66535aF65AaC99C32e9eA844e14501',
@@ -111,8 +111,8 @@ exports.POOLS_DATA_FANTOM = (0, utils_1.lowerCasePoolDataAddresses)({
111
111
  gauge_address: '0x319E268f0A4C85D404734ee7958857F5891506d7',
112
112
  is_crypto: true,
113
113
  is_plain: true,
114
- underlying_coins: ['fUSDT', 'BTC', 'ETH'],
115
- wrapped_coins: ['fUSDT', 'BTC', 'ETH'],
114
+ underlying_coins: ['fUSDT', 'WBTC', 'ETH'],
115
+ wrapped_coins: ['fUSDT', 'WBTC', 'ETH'],
116
116
  underlying_coin_addresses: [
117
117
  '0x049d68029688eAbF473097a2fC38ef61633A3C7A',
118
118
  '0x321162Cd933E2Be498Cd2267a90534A804051b11',
@@ -57,6 +57,7 @@ export declare class PoolTemplate {
57
57
  };
58
58
  stats: {
59
59
  parameters: () => Promise<{
60
+ lpTokenSupply: string;
60
61
  virtualPrice: string;
61
62
  fee: string;
62
63
  adminFee: string;
@@ -66,6 +67,8 @@ export declare class PoolTemplate {
66
67
  future_A_time?: number;
67
68
  initial_A_time?: number;
68
69
  gamma?: string;
70
+ price_oracle?: string[];
71
+ price_scale?: string[];
69
72
  }>;
70
73
  underlyingBalances: () => Promise<string[]>;
71
74
  wrappedBalances: () => Promise<string[]>;
@@ -74,8 +74,8 @@ var PoolTemplate = /** @class */ (function () {
74
74
  function PoolTemplate(id) {
75
75
  var _this = this;
76
76
  this.statsParameters = function () { return __awaiter(_this, void 0, void 0, function () {
77
- var multicallContract, lpMulticallContract, calls, additionalCalls, _c, _virtualPrice, _lpTokenSupply, _fee, _adminFee, _A, _gamma, e_1, _d, virtualPrice, lpTokenSupply, fee, adminFee, A, gamma, A_PRECISION, _e, _future_A, _initial_A, _future_A_time, _initial_A_time, _f, future_A, initial_A, future_A_time, initial_A_time;
78
- var _g, _h;
77
+ var multicallContract, lpMulticallContract, calls, i, additionalCalls, _virtualPrice, _fee, _prices, _adminFee, _A, _lpTokenSupply, _gamma, e_1, _c, virtualPrice, fee, adminFee, A, lpTokenSupply, gamma, priceOracle, priceScale, prices, i, A_PRECISION, _d, _future_A, _initial_A, _future_A_time, _initial_A_time, _e, future_A, initial_A, future_A_time, initial_A_time;
78
+ var _f, _g, _h;
79
79
  return __generator(this, function (_j) {
80
80
  switch (_j.label) {
81
81
  case 0:
@@ -83,52 +83,80 @@ var PoolTemplate = /** @class */ (function () {
83
83
  lpMulticallContract = curve_1.curve.contracts[this.lpToken].multicallContract;
84
84
  calls = [
85
85
  multicallContract.get_virtual_price(),
86
- lpMulticallContract.totalSupply(),
87
86
  multicallContract.fee(),
88
87
  multicallContract.admin_fee(),
89
88
  multicallContract.A(),
89
+ lpMulticallContract.totalSupply(),
90
90
  ];
91
- if (this.isCrypto)
91
+ if (this.isCrypto) {
92
92
  calls.push(multicallContract.gamma());
93
+ if (this.wrappedCoins.length === 2) {
94
+ calls.push(multicallContract.price_oracle());
95
+ calls.push(multicallContract.price_scale());
96
+ }
97
+ else {
98
+ for (i = 0; i < this.wrappedCoins.length - 1; i++) {
99
+ calls.push(multicallContract.price_oracle(i));
100
+ calls.push(multicallContract.price_scale(i));
101
+ }
102
+ }
103
+ }
93
104
  additionalCalls = this.isCrypto ? [] : [multicallContract.future_A()];
94
105
  if ('initial_A' in multicallContract) {
95
106
  additionalCalls.push(multicallContract.initial_A(), multicallContract.future_A_time(), multicallContract.initial_A_time());
96
107
  }
97
- _c = Array(6).fill(ethers_1.ethers.BigNumber.from(0)), _virtualPrice = _c[0], _lpTokenSupply = _c[1], _fee = _c[2], _adminFee = _c[3], _A = _c[4], _gamma = _c[5];
108
+ _virtualPrice = ethers_1.ethers.BigNumber.from(0);
109
+ _fee = ethers_1.ethers.BigNumber.from(0);
98
110
  _j.label = 1;
99
111
  case 1:
100
- _j.trys.push([1, 3, , 5]);
112
+ _j.trys.push([1, 3, , 8]);
101
113
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
102
114
  case 2:
103
- _g = (_j.sent()), _virtualPrice = _g[0], _lpTokenSupply = _g[1], _fee = _g[2], _adminFee = _g[3], _A = _g[4], _gamma = _g[5];
104
- return [3 /*break*/, 5];
115
+ _f = (_j.sent()), _virtualPrice = _f[0], _fee = _f[1], _adminFee = _f[2], _A = _f[3], _lpTokenSupply = _f[4], _gamma = _f[5], _prices = _f.slice(6);
116
+ return [3 /*break*/, 8];
105
117
  case 3:
106
118
  e_1 = _j.sent();
107
119
  calls.shift();
120
+ if (!this.isCrypto) return [3 /*break*/, 5];
121
+ calls.shift();
108
122
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
109
123
  case 4:
110
- _h = (_j.sent()), _lpTokenSupply = _h[0], _fee = _h[1], _adminFee = _h[2], _A = _h[3], _gamma = _h[4];
111
- return [3 /*break*/, 5];
112
- case 5:
113
- _d = [
124
+ _g = (_j.sent()), _adminFee = _g[0], _A = _g[1], _lpTokenSupply = _g[2], _gamma = _g[3], _prices = _g.slice(4);
125
+ return [3 /*break*/, 7];
126
+ case 5: return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
127
+ case 6:
128
+ _h = (_j.sent()), _fee = _h[0], _adminFee = _h[1], _A = _h[2], _lpTokenSupply = _h[3], _gamma = _h[4], _prices = _h.slice(5);
129
+ _j.label = 7;
130
+ case 7: return [3 /*break*/, 8];
131
+ case 8:
132
+ _c = [
114
133
  ethers_1.ethers.utils.formatUnits(_virtualPrice),
115
- ethers_1.ethers.utils.formatUnits(_lpTokenSupply),
116
134
  ethers_1.ethers.utils.formatUnits(_fee, 8),
117
135
  ethers_1.ethers.utils.formatUnits(_adminFee.mul(_fee)),
118
136
  ethers_1.ethers.utils.formatUnits(_A, 0),
137
+ ethers_1.ethers.utils.formatUnits(_lpTokenSupply),
119
138
  _gamma ? ethers_1.ethers.utils.formatUnits(_gamma) : _gamma,
120
- ], virtualPrice = _d[0], lpTokenSupply = _d[1], fee = _d[2], adminFee = _d[3], A = _d[4], gamma = _d[5];
139
+ ], virtualPrice = _c[0], fee = _c[1], adminFee = _c[2], A = _c[3], lpTokenSupply = _c[4], gamma = _c[5];
140
+ if (this.isCrypto) {
141
+ prices = _prices.map(function (_p) { return ethers_1.ethers.utils.formatUnits(_p); });
142
+ priceOracle = [];
143
+ priceScale = [];
144
+ for (i = 0; i < this.wrappedCoins.length - 1; i++) {
145
+ priceOracle.push(prices.shift());
146
+ priceScale.push(prices.shift());
147
+ }
148
+ }
121
149
  A_PRECISION = curve_1.curve.chainId === 1 && ['compound', 'usdt', 'y', 'busd', 'susd', 'pax', 'ren', 'sbtc', 'hbtc', '3pool'].includes(this.id) ? 1 : 100;
122
150
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(additionalCalls)];
123
- case 6:
124
- _e = _j.sent(), _future_A = _e[0], _initial_A = _e[1], _future_A_time = _e[2], _initial_A_time = _e[3];
125
- _f = [
151
+ case 9:
152
+ _d = _j.sent(), _future_A = _d[0], _initial_A = _d[1], _future_A_time = _d[2], _initial_A_time = _d[3];
153
+ _e = [
126
154
  _future_A ? String(Number(ethers_1.ethers.utils.formatUnits(_future_A, 0)) / A_PRECISION) : undefined,
127
155
  _initial_A ? String(Number(ethers_1.ethers.utils.formatUnits(_initial_A, 0)) / A_PRECISION) : undefined,
128
156
  _future_A_time ? Number(ethers_1.ethers.utils.formatUnits(_future_A_time, 0)) * 1000 : undefined,
129
157
  _initial_A_time ? Number(ethers_1.ethers.utils.formatUnits(_initial_A_time, 0)) * 1000 : undefined,
130
- ], future_A = _f[0], initial_A = _f[1], future_A_time = _f[2], initial_A_time = _f[3];
131
- return [2 /*return*/, { virtualPrice: virtualPrice, lpTokenSupply: lpTokenSupply, fee: fee, adminFee: adminFee, A: A, future_A: future_A, initial_A: initial_A, future_A_time: future_A_time, initial_A_time: initial_A_time, gamma: gamma }];
158
+ ], future_A = _e[0], initial_A = _e[1], future_A_time = _e[2], initial_A_time = _e[3];
159
+ return [2 /*return*/, { lpTokenSupply: lpTokenSupply, virtualPrice: virtualPrice, fee: fee, adminFee: adminFee, A: A, future_A: future_A, initial_A: initial_A, future_A_time: future_A_time, initial_A_time: initial_A_time, gamma: gamma, priceOracle: priceOracle, priceScale: priceScale }];
132
160
  }
133
161
  });
134
162
  }); };
@@ -1969,8 +1997,8 @@ var PoolTemplate = /** @class */ (function () {
1969
1997
  PoolTemplate.prototype._depositAndStake = function (amounts, isUnderlying, estimateGas) {
1970
1998
  return __awaiter(this, void 0, void 0, function () {
1971
1999
  var coinAddresses, coins, decimals, depositAddress, balances, _c, _d, _e, _f, _g, i, allowance, _h, _amounts, contract, useUnderlying, _minMintAmount, _j, _k, _l, _m, _o, ethIndex, value, i, _gas, gasLimit;
1972
- return __generator(this, function (_p) {
1973
- switch (_p.label) {
2000
+ return __generator(this, function (_q) {
2001
+ switch (_q.label) {
1974
2002
  case 0:
1975
2003
  coinAddresses = isUnderlying ? __spreadArray([], this.underlyingCoinAddresses, true) : __spreadArray([], this.wrappedCoinAddresses, true);
1976
2004
  coins = isUnderlying ? this.underlyingCoins : this.wrappedCoinAddresses;
@@ -1983,14 +2011,14 @@ var PoolTemplate = /** @class */ (function () {
1983
2011
  _e = (_d = Object).values;
1984
2012
  return [4 /*yield*/, this.walletUnderlyingCoinBalances()];
1985
2013
  case 1:
1986
- _c = _e.apply(_d, [_p.sent()]);
2014
+ _c = _e.apply(_d, [_q.sent()]);
1987
2015
  return [3 /*break*/, 4];
1988
2016
  case 2:
1989
2017
  _g = (_f = Object).values;
1990
2018
  return [4 /*yield*/, this.walletWrappedCoinBalances()];
1991
2019
  case 3:
1992
- _c = _g.apply(_f, [_p.sent()]);
1993
- _p.label = 4;
2020
+ _c = _g.apply(_f, [_q.sent()]);
2021
+ _q.label = 4;
1994
2022
  case 4:
1995
2023
  balances = _c;
1996
2024
  for (i = 0; i < balances.length; i++) {
@@ -2001,12 +2029,12 @@ var PoolTemplate = /** @class */ (function () {
2001
2029
  if (!isUnderlying) return [3 /*break*/, 6];
2002
2030
  return [4 /*yield*/, this.depositAndStakeIsApproved(amounts)];
2003
2031
  case 5:
2004
- _h = _p.sent();
2032
+ _h = _q.sent();
2005
2033
  return [3 /*break*/, 8];
2006
2034
  case 6: return [4 /*yield*/, this.depositAndStakeWrappedIsApproved(amounts)];
2007
2035
  case 7:
2008
- _h = _p.sent();
2009
- _p.label = 8;
2036
+ _h = _q.sent();
2037
+ _q.label = 8;
2010
2038
  case 8:
2011
2039
  allowance = _h;
2012
2040
  if (estimateGas && !allowance) {
@@ -2016,12 +2044,12 @@ var PoolTemplate = /** @class */ (function () {
2016
2044
  if (!isUnderlying) return [3 /*break*/, 10];
2017
2045
  return [4 /*yield*/, this.depositAndStakeApprove(amounts)];
2018
2046
  case 9:
2019
- _p.sent();
2047
+ _q.sent();
2020
2048
  return [3 /*break*/, 12];
2021
2049
  case 10: return [4 /*yield*/, this.depositAndStakeWrappedApprove(amounts)];
2022
2050
  case 11:
2023
- _p.sent();
2024
- _p.label = 12;
2051
+ _q.sent();
2052
+ _q.label = 12;
2025
2053
  case 12:
2026
2054
  _amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, decimals[i]); });
2027
2055
  contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.deposit_and_stake].contract;
@@ -2030,14 +2058,14 @@ var PoolTemplate = /** @class */ (function () {
2030
2058
  _l = (_k = ethers_1.ethers.utils).parseUnits;
2031
2059
  return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
2032
2060
  case 13:
2033
- _j = _l.apply(_k, [_p.sent()]).mul(99).div(100);
2061
+ _j = _l.apply(_k, [_q.sent()]).mul(99).div(100);
2034
2062
  return [3 /*break*/, 16];
2035
2063
  case 14:
2036
2064
  _o = (_m = ethers_1.ethers.utils).parseUnits;
2037
2065
  return [4 /*yield*/, this.depositAndStakeWrappedExpected(amounts)];
2038
2066
  case 15:
2039
- _j = _o.apply(_m, [_p.sent()]).mul(99).div(100);
2040
- _p.label = 16;
2067
+ _j = _o.apply(_m, [_q.sent()]).mul(99).div(100);
2068
+ _q.label = 16;
2041
2069
  case 16:
2042
2070
  _minMintAmount = _j;
2043
2071
  ethIndex = (0, utils_1.getEthIndex)(coinAddresses);
@@ -2048,15 +2076,15 @@ var PoolTemplate = /** @class */ (function () {
2048
2076
  }
2049
2077
  return [4 /*yield*/, contract.estimateGas.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isMetaFactory && isUnderlying ? this.address : ethers_1.ethers.constants.AddressZero, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
2050
2078
  case 17:
2051
- _gas = (_p.sent());
2079
+ _gas = (_q.sent());
2052
2080
  if (estimateGas)
2053
2081
  return [2 /*return*/, _gas.toNumber()];
2054
2082
  return [4 /*yield*/, curve_1.curve.updateFeeData()];
2055
2083
  case 18:
2056
- _p.sent();
2084
+ _q.sent();
2057
2085
  gasLimit = _gas.mul(200).div(100);
2058
2086
  return [4 /*yield*/, contract.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isMetaFactory && isUnderlying ? this.address : ethers_1.ethers.constants.AddressZero, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
2059
- case 19: return [2 /*return*/, (_p.sent()).hash];
2087
+ case 19: return [2 /*return*/, (_q.sent()).hash];
2060
2088
  }
2061
2089
  });
2062
2090
  });
@@ -2645,17 +2673,17 @@ var PoolTemplate = /** @class */ (function () {
2645
2673
  return [3 /*break*/, 5];
2646
2674
  case 3:
2647
2675
  _d = (_c = ethers_1.ethers.utils).formatUnits;
2648
- return [4 /*yield*/, curve_1.curve.contracts[this.lpToken].contract.totalSupply()];
2676
+ return [4 /*yield*/, curve_1.curve.contracts[this.lpToken].contract.totalSupply(curve_1.curve.constantOptions)];
2649
2677
  case 4:
2650
2678
  totalLp = _d.apply(_c, [_f.sent()]);
2651
2679
  _f.label = 5;
2652
2680
  case 5: return [2 /*return*/, {
2653
2681
  lpUser: userLpTotalBalanceBN.toString(),
2654
2682
  lpTotal: totalLp,
2655
- lpShare: userLpTotalBalanceBN.div(totalLp).times(100).toString(),
2683
+ lpShare: (0, utils_1.BN)(totalLp).gt(0) ? userLpTotalBalanceBN.div(totalLp).times(100).toString() : '0',
2656
2684
  gaugeUser: userLpBalance.gauge,
2657
2685
  gaugeTotal: gaugeLp,
2658
- gaugeShare: withGauge ? (0, utils_1.BN)(userLpBalance.gauge).div((0, utils_1.BN)(gaugeLp)).times(100).toString() : undefined,
2686
+ gaugeShare: !withGauge ? undefined : (0, utils_1.BN)(gaugeLp).gt(0) ? (0, utils_1.BN)(userLpBalance.gauge).div(gaugeLp).times(100).toString() : '0',
2659
2687
  }];
2660
2688
  }
2661
2689
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.21.2",
3
+ "version": "2.21.3",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",