Skip to content

Commit

Permalink
Merge pull request #397 from curvefi/feat/add-support-old-gauge-factory
Browse files Browse the repository at this point in the history
feat: add support old gauge factory
  • Loading branch information
fedorovdg authored Sep 27, 2024
2 parents e213f8c + 4337dc9 commit 79fe005
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@curvefi/api",
"version": "2.63.6",
"version": "2.63.7",
"description": "JavaScript library for curve.fi",
"main": "lib/index.js",
"author": "Macket",
Expand Down
2 changes: 1 addition & 1 deletion src/constants/aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const ALIASES_OPTIMISM = lowerCaseValues({

export const ALIASES_XDAI = lowerCaseValues({
"crv": "0x712b3d230f3c1c19db860d80619288b1f0bdd0bd",
"child_gauge_factory": "0x7BE6BD57A319A7180f71552E58c9d32Da32b6f96",
"child_gauge_factory": "0x06471ED238306a427241B3eA81352244E77B004F",
"root_gauge_factory": "0x06471ED238306a427241B3eA81352244E77B004F",
"child_gauge_factory_old": "0xabC000d88f23Bb45525E447528DBF656A9D55bf5",
"voting_escrow": "0xefde221f306152971d8e9f181bfe998447975810",
Expand Down
64 changes: 58 additions & 6 deletions src/pools/PoolTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -993,25 +993,77 @@ export class PoolTemplate {

public async claimCrvEstimateGas(): Promise<number | number[]> {
if (this.rewardsOnly()) throw Error(`${this.name} has Rewards-Only Gauge. Use claimRewards instead`);
if(curve.chainId === 1) {
return Number(await curve.contracts[curve.constants.ALIASES.minter].contract.mint.estimateGas(this.gauge.address, curve.constantOptions));

let isOldFactory = false;
let contract;

if (curve.chainId !== 1) {
if (curve.constants.ALIASES.child_gauge_factory_old && curve.constants.ALIASES.child_gauge_factory_old !== curve.constants.ZERO_ADDRESS) {
const oldFactoryContract = curve.contracts[curve.constants.ALIASES.child_gauge_factory_old].contract;
const gaugeAddress = await oldFactoryContract.get_gauge_from_lp_token(this.lpToken);

isOldFactory = gaugeAddress === this.gauge.address;

if (isOldFactory) {
contract = oldFactoryContract;
}
}
}

if (!isOldFactory) {
contract = curve.chainId === 1 ?
curve.contracts[curve.constants.ALIASES.minter].contract :
curve.contracts[curve.constants.ALIASES.child_gauge_factory].contract;
}

if (!contract) {
throw new Error("Failed to find the correct contract for estimating gas");
}

if (curve.chainId === 1) {
return Number(await contract.mint.estimateGas(this.gauge.address, curve.constantOptions));
} else {
return smartNumber(await curve.contracts[curve.constants.ALIASES.child_gauge_factory].contract.mint.estimateGas(this.gauge.address, curve.constantOptions));
return smartNumber(await contract.mint.estimateGas(this.gauge.address, curve.constantOptions));
}
}


public async claimCrv(): Promise<string> {
if (this.rewardsOnly()) throw Error(`${this.name} has Rewards-Only Gauge. Use claimRewards instead`);
const contract = curve.chainId === 1 ?
curve.contracts[curve.constants.ALIASES.minter].contract :
curve.contracts[curve.constants.ALIASES.child_gauge_factory].contract;

let isOldFactory = false;
let contract;

if (curve.chainId !== 1) {
if (curve.constants.ALIASES.child_gauge_factory_old && curve.constants.ALIASES.child_gauge_factory_old !== curve.constants.ZERO_ADDRESS) {
const oldFactoryContract = curve.contracts[curve.constants.ALIASES.child_gauge_factory_old].contract;
const gaugeAddress = await oldFactoryContract.get_gauge_from_lp_token(this.lpToken);

isOldFactory = gaugeAddress === this.gauge.address;

if (isOldFactory) {
contract = oldFactoryContract;
}
}
}

if (!isOldFactory) {
contract = curve.chainId === 1 ?
curve.contracts[curve.constants.ALIASES.minter].contract :
curve.contracts[curve.constants.ALIASES.child_gauge_factory].contract;
}

if (!contract) {
throw new Error("Failed to find the correct contract for minting");
}

await curve.updateFeeData();

const gasLimit = mulBy1_3(DIGas(await contract.mint.estimateGas(this.gauge.address, curve.constantOptions)));
return (await contract.mint(this.gauge.address, { ...curve.options, gasLimit })).hash;
}


public userBoost = async (address = ""): Promise<string> => {
if (this.gauge.address === curve.constants.ZERO_ADDRESS) throw Error(`${this.name} doesn't have gauge`);
if (this.rewardsOnly()) throw Error(`${this.name} has Rewards-Only Gauge. Use stats.rewardsApy instead`);
Expand Down

0 comments on commit 79fe005

Please sign in to comment.