@curvefi/api 2.65.29 → 2.66.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/lib/curve.d.ts +9 -1
- package/lib/curve.js +42 -9
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,9 @@ import curve from "@curvefi/api";
|
|
|
21
21
|
|
|
22
22
|
// 3. Web3 provider
|
|
23
23
|
await curve.init('Web3', { externalProvider: <WEB3_PROVIDER> }, { chainId: 1 });
|
|
24
|
+
|
|
25
|
+
// 4. Without RPC
|
|
26
|
+
await curve.init('NoRPC', {chainId: 1, networkName: 'ETHEREUM'});
|
|
24
27
|
|
|
25
28
|
// Fetch factory pools
|
|
26
29
|
await curve.factory.fetchPools();
|
package/lib/curve.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ export type ContractItem = {
|
|
|
11
11
|
};
|
|
12
12
|
declare class Curve implements ICurve {
|
|
13
13
|
provider: ethers.BrowserProvider | ethers.JsonRpcProvider;
|
|
14
|
+
chainOptions?: {
|
|
15
|
+
chainId: number;
|
|
16
|
+
name: string;
|
|
17
|
+
};
|
|
18
|
+
isNoRPC: boolean;
|
|
14
19
|
multicallProvider: MulticallProvider;
|
|
15
20
|
signer: ethers.Signer | null;
|
|
16
21
|
signerAddress: string;
|
|
@@ -35,7 +40,7 @@ declare class Curve implements ICurve {
|
|
|
35
40
|
L1WeightedGasPrice?: number;
|
|
36
41
|
constants: INetworkConstants;
|
|
37
42
|
constructor();
|
|
38
|
-
init(providerType: 'JsonRpc' | 'Web3' | 'Infura' | 'Alchemy', providerSettings: {
|
|
43
|
+
init(providerType: 'JsonRpc' | 'Web3' | 'Infura' | 'Alchemy' | 'NoRPC', providerSettings: {
|
|
39
44
|
url?: string;
|
|
40
45
|
privateKey?: string;
|
|
41
46
|
batchMaxCount?: number;
|
|
@@ -44,6 +49,9 @@ declare class Curve implements ICurve {
|
|
|
44
49
|
} | {
|
|
45
50
|
network?: Networkish;
|
|
46
51
|
apiKey?: string;
|
|
52
|
+
} | {
|
|
53
|
+
chainId: number;
|
|
54
|
+
networkName: string;
|
|
47
55
|
}, options?: {
|
|
48
56
|
gasPrice?: number;
|
|
49
57
|
maxFeePerGas?: number;
|
package/lib/curve.js
CHANGED
|
@@ -95,7 +95,7 @@ class Curve {
|
|
|
95
95
|
}
|
|
96
96
|
this.constants.FACTORY_POOLS_DATA = yield this._filterHiddenPools(this.constants.FACTORY_POOLS_DATA);
|
|
97
97
|
this._updateDecimalsAndGauges(this.constants.FACTORY_POOLS_DATA);
|
|
98
|
-
this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory"] = yield this.contracts[this.constants.ALIASES.factory].contract.gauge_implementation(this.constantOptions);
|
|
98
|
+
this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory"] = this.isNoRPC ? null : yield this.contracts[this.constants.ALIASES.factory].contract.gauge_implementation(this.constantOptions);
|
|
99
99
|
});
|
|
100
100
|
this.fetchCrvusdFactoryPools = (...args_1) => __awaiter(this, [...args_1], void 0, function* (useApi = true) {
|
|
101
101
|
if (!("crvusd_factory" in this.constants.ALIASES))
|
|
@@ -104,6 +104,9 @@ class Curve {
|
|
|
104
104
|
this.constants.CRVUSD_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolsDataFromApi.call(this, "factory-crvusd"));
|
|
105
105
|
}
|
|
106
106
|
else {
|
|
107
|
+
if (this.isNoRPC) {
|
|
108
|
+
throw new Error('RPC connection is required');
|
|
109
|
+
}
|
|
107
110
|
this.constants.CRVUSD_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolData.call(this, 0, undefined, this.constants.ALIASES.crvusd_factory));
|
|
108
111
|
}
|
|
109
112
|
this.constants.CRVUSD_FACTORY_POOLS_DATA = yield this._filterHiddenPools(this.constants.CRVUSD_FACTORY_POOLS_DATA);
|
|
@@ -116,6 +119,9 @@ class Curve {
|
|
|
116
119
|
this.constants.EYWA_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolsDataFromApi.call(this, "factory-eywa"));
|
|
117
120
|
}
|
|
118
121
|
else {
|
|
122
|
+
if (this.isNoRPC) {
|
|
123
|
+
throw new Error('RPC connection is required');
|
|
124
|
+
}
|
|
119
125
|
this.constants.EYWA_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolData.call(this, 0, undefined, this.constants.ALIASES.eywa_factory));
|
|
120
126
|
}
|
|
121
127
|
this.constants.EYWA_FACTORY_POOLS_DATA = yield this._filterHiddenPools(this.constants.EYWA_FACTORY_POOLS_DATA);
|
|
@@ -128,11 +134,14 @@ class Curve {
|
|
|
128
134
|
this.constants.CRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolsDataFromApi.call(this, "factory-crypto"));
|
|
129
135
|
}
|
|
130
136
|
else {
|
|
137
|
+
if (this.isNoRPC) {
|
|
138
|
+
throw new Error('RPC connection is required');
|
|
139
|
+
}
|
|
131
140
|
this.constants.CRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getCryptoFactoryPoolData.call(this));
|
|
132
141
|
}
|
|
133
142
|
this.constants.CRYPTO_FACTORY_POOLS_DATA = yield this._filterHiddenPools(this.constants.CRYPTO_FACTORY_POOLS_DATA);
|
|
134
143
|
this._updateDecimalsAndGauges(this.constants.CRYPTO_FACTORY_POOLS_DATA);
|
|
135
|
-
this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory-crypto"] = yield this.contracts[this.constants.ALIASES.crypto_factory].contract.gauge_implementation(this.constantOptions);
|
|
144
|
+
this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory-crypto"] = this.isNoRPC ? null : yield this.contracts[this.constants.ALIASES.crypto_factory].contract.gauge_implementation(this.constantOptions);
|
|
136
145
|
});
|
|
137
146
|
this.fetchStableNgFactoryPools = (...args_1) => __awaiter(this, [...args_1], void 0, function* (useApi = true) {
|
|
138
147
|
if (!("stable_ng_factory" in this.constants.ALIASES))
|
|
@@ -141,6 +150,9 @@ class Curve {
|
|
|
141
150
|
this.constants.STABLE_NG_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolsDataFromApi.call(this, "factory-stable-ng"));
|
|
142
151
|
}
|
|
143
152
|
else {
|
|
153
|
+
if (this.isNoRPC) {
|
|
154
|
+
throw new Error('RPC connection is required');
|
|
155
|
+
}
|
|
144
156
|
this.constants.STABLE_NG_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolData.call(this, 0, undefined, this.constants.ALIASES.stable_ng_factory));
|
|
145
157
|
}
|
|
146
158
|
this.constants.STABLE_NG_FACTORY_POOLS_DATA = yield this._filterHiddenPools(this.constants.STABLE_NG_FACTORY_POOLS_DATA);
|
|
@@ -153,16 +165,19 @@ class Curve {
|
|
|
153
165
|
this.constants.TWOCRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolsDataFromApi.call(this, "factory-twocrypto"));
|
|
154
166
|
}
|
|
155
167
|
else {
|
|
168
|
+
if (this.isNoRPC) {
|
|
169
|
+
throw new Error('RPC connection is required');
|
|
170
|
+
}
|
|
156
171
|
this.constants.TWOCRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getTwocryptoFactoryPoolData.call(this));
|
|
157
172
|
}
|
|
158
173
|
this.constants.TWOCRYPTO_FACTORY_POOLS_DATA = yield this._filterHiddenPools(this.constants.TWOCRYPTO_FACTORY_POOLS_DATA);
|
|
159
174
|
this._updateDecimalsAndGauges(this.constants.TWOCRYPTO_FACTORY_POOLS_DATA);
|
|
160
175
|
if (this.chainId === 1) {
|
|
161
|
-
this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory-twocrypto"] =
|
|
176
|
+
this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory-twocrypto"] = this.isNoRPC ? null :
|
|
162
177
|
yield this.contracts[this.constants.ALIASES.twocrypto_factory].contract.gauge_implementation(this.constantOptions);
|
|
163
178
|
}
|
|
164
179
|
else {
|
|
165
|
-
this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory-twocrypto"] =
|
|
180
|
+
this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory-twocrypto"] = this.isNoRPC ? null :
|
|
166
181
|
yield this.contracts[this.constants.ALIASES.child_gauge_factory].contract.get_implementation(this.constantOptions);
|
|
167
182
|
}
|
|
168
183
|
});
|
|
@@ -173,16 +188,19 @@ class Curve {
|
|
|
173
188
|
this.constants.TRICRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getFactoryPoolsDataFromApi.call(this, "factory-tricrypto"));
|
|
174
189
|
}
|
|
175
190
|
else {
|
|
191
|
+
if (this.isNoRPC) {
|
|
192
|
+
throw new Error('RPC connection is required');
|
|
193
|
+
}
|
|
176
194
|
this.constants.TRICRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(yield getTricryptoFactoryPoolData.call(this));
|
|
177
195
|
}
|
|
178
196
|
this.constants.TRICRYPTO_FACTORY_POOLS_DATA = yield this._filterHiddenPools(this.constants.TRICRYPTO_FACTORY_POOLS_DATA);
|
|
179
197
|
this._updateDecimalsAndGauges(this.constants.TRICRYPTO_FACTORY_POOLS_DATA);
|
|
180
198
|
if (this.chainId === 1) {
|
|
181
|
-
this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory-tricrypto"] =
|
|
199
|
+
this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory-tricrypto"] = this.isNoRPC ? null :
|
|
182
200
|
yield this.contracts[this.constants.ALIASES.tricrypto_factory].contract.gauge_implementation(this.constantOptions);
|
|
183
201
|
}
|
|
184
202
|
else {
|
|
185
|
-
this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory-tricrypto"] =
|
|
203
|
+
this.constants.FACTORY_GAUGE_IMPLEMENTATIONS["factory-tricrypto"] = this.isNoRPC ? null :
|
|
186
204
|
yield this.contracts[this.constants.ALIASES.child_gauge_factory].contract.get_implementation(this.constantOptions);
|
|
187
205
|
}
|
|
188
206
|
});
|
|
@@ -308,6 +326,7 @@ class Curve {
|
|
|
308
326
|
this.provider = null;
|
|
309
327
|
// @ts-ignore
|
|
310
328
|
this.signer = null;
|
|
329
|
+
this.isNoRPC = false;
|
|
311
330
|
this.signerAddress = '';
|
|
312
331
|
this.chainId = 1;
|
|
313
332
|
this.isLiteChain = false;
|
|
@@ -425,10 +444,19 @@ class Curve {
|
|
|
425
444
|
this.provider = new ethers.AlchemyProvider(providerSettings.network, providerSettings.apiKey);
|
|
426
445
|
this.signer = null;
|
|
427
446
|
}
|
|
447
|
+
else if (providerType.toLowerCase() === 'NoRPC'.toLowerCase()) {
|
|
448
|
+
providerSettings = providerSettings;
|
|
449
|
+
this.isNoRPC = true;
|
|
450
|
+
this.chainOptions = {
|
|
451
|
+
chainId: providerSettings.chainId,
|
|
452
|
+
name: providerSettings.networkName,
|
|
453
|
+
};
|
|
454
|
+
this.signer = null;
|
|
455
|
+
}
|
|
428
456
|
else {
|
|
429
457
|
throw Error('Wrong providerType');
|
|
430
458
|
}
|
|
431
|
-
const network = yield this.provider.getNetwork();
|
|
459
|
+
const network = this.chainOptions || (yield this.provider.getNetwork());
|
|
432
460
|
console.log("CURVE-JS IS CONNECTED TO NETWORK:", { name: network.name.toUpperCase(), chainId: Number(network.chainId) });
|
|
433
461
|
this.chainId = Number(network.chainId) === 133 || Number(network.chainId) === 31337 ? 1 : Number(network.chainId);
|
|
434
462
|
this.isLiteChain = !(this.chainId in NETWORK_CONSTANTS);
|
|
@@ -563,8 +591,10 @@ class Curve {
|
|
|
563
591
|
if ("factory" in this.constants.ALIASES) {
|
|
564
592
|
this.setContract(this.constants.ALIASES.factory, factoryABI);
|
|
565
593
|
const factoryContract = this.contracts[this.constants.ALIASES.factory].contract;
|
|
566
|
-
|
|
567
|
-
|
|
594
|
+
if (!this.isNoRPC) {
|
|
595
|
+
this.constants.ALIASES.factory_admin = (yield factoryContract.admin(this.constantOptions)).toLowerCase();
|
|
596
|
+
this.setContract(this.constants.ALIASES.factory_admin, factoryAdminABI);
|
|
597
|
+
}
|
|
568
598
|
}
|
|
569
599
|
this.setContract(this.constants.ALIASES.crvusd_factory, factoryABI);
|
|
570
600
|
this.setContract(this.constants.ALIASES.eywa_factory, factoryEywaABI);
|
|
@@ -676,6 +706,9 @@ class Curve {
|
|
|
676
706
|
}
|
|
677
707
|
updateFeeData() {
|
|
678
708
|
return __awaiter(this, void 0, void 0, function* () {
|
|
709
|
+
if (this.isNoRPC) {
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
679
712
|
const feeData = yield this.provider.getFeeData();
|
|
680
713
|
if (feeData.maxFeePerGas === null || feeData.maxPriorityFeePerGas === null) {
|
|
681
714
|
delete this.options.maxFeePerGas;
|
package/lib/index.d.ts
CHANGED
|
@@ -65,6 +65,7 @@ declare const curve: {
|
|
|
65
65
|
getCurveLiteNetworks: () => Promise<import("./interfaces.js").ICurveLiteNetwork[]>;
|
|
66
66
|
getNetworkConstants: () => import("./interfaces.js").INetworkConstants;
|
|
67
67
|
getIsLiteChain: () => boolean;
|
|
68
|
+
isNoRPC: boolean;
|
|
68
69
|
factory: {
|
|
69
70
|
fetchPools: (useApi?: boolean) => Promise<void>;
|
|
70
71
|
fetchNewPools: () => Promise<string[]>;
|
package/lib/index.js
CHANGED
|
@@ -22,6 +22,8 @@ function init(providerType_1, providerSettings_1) {
|
|
|
22
22
|
this.signerAddress = _curve.signerAddress;
|
|
23
23
|
// @ts-ignore
|
|
24
24
|
this.chainId = _curve.chainId;
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
this.isNoRPC = _curve.isNoRPC;
|
|
25
27
|
});
|
|
26
28
|
}
|
|
27
29
|
function setCustomFeeData(customFeeData) {
|
|
@@ -59,6 +61,7 @@ const curve = {
|
|
|
59
61
|
getCurveLiteNetworks,
|
|
60
62
|
getNetworkConstants: _curve.getNetworkConstants,
|
|
61
63
|
getIsLiteChain: _curve.getIsLiteChain,
|
|
64
|
+
isNoRPC: _curve.isNoRPC,
|
|
62
65
|
factory: {
|
|
63
66
|
fetchPools: _curve.fetchFactoryPools,
|
|
64
67
|
fetchNewPools: _curve.fetchNewFactoryPools,
|