Skip to content

Commit

Permalink
Merge pull request #239 from curvefi/feat/add-deploy-gauge
Browse files Browse the repository at this point in the history
feat: add deploy gauge for stable-ng-factory
  • Loading branch information
fedorovdg authored Dec 10, 2023
2 parents 97703d8 + bfbab8a commit 3057895
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 3 deletions.
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,36 @@ import curve from "@curvefi/api";

const poolAddress = await curve.stableNgFactory.getDeployedPlainPoolAddress(deployPoolTx);
// 0x0816bc9ced716008c88bb8940c297e9c9167755e

// Deploy gauge

const deployGaugeTx = await curve.stableNgFactory.deployGauge(poolAddress);
// {
// hash: '0x8bb0eb63430e6c522c30922a833fee263816ebc0f30367d53ecfe52e17b7c3a0',
// type: 0,
// accessList: null,
// ...
// }
const gaugeAddress = await curve.stableNgFactory.getDeployedGaugeAddress(deployGaugeTx);
// 0x1400e08f1d9f5bc90ae19acd4bf81beabc9e79de

//For sidechain
const salt = '15'
//salt - unical random string
const deployGaugeSidechain = await curve.stableNgFactory.deployGaugeSidechain(poolAddress, salt);
// ContractTransactionResponse {
// provider: JsonRpcProvider {},
// blockNumber: 17393463,
// blockHash: '0x7f393493d7eb30b39aeef3118b51925426946eb83b72b18946f0da8c7bec40a0',
// ...
// }
const gaugeSidechainAddress = await curve.stableNgFactory.getDeployedGaugeAddress(deployGaugeSidechain);
// 0x60d3d7ebbc44dc810a743703184f062d00e6db7e
//After that should be deployed mirror gauge on mainnet with same salt
//const gaugeMirrorTx = await curve.stableNgFactory.deployGaugeMirror(sidechainId, salt);
//const deployedGaugeMirrorAddress = await curve.stableNgFactory.getDeployedGaugeMirrorAddressByTx(gaugeMirrorTx);
//OR
//const deployedGaugeMirrorAddress = await curve.stableNgFactory.getDeployedGaugeMirrorAddress(sidechainId);
})()
```
Expand Down Expand Up @@ -1746,6 +1776,37 @@ import curve from "@curvefi/api";
// }
const poolAddress = await curve.factory.getDeployedMetaPoolAddress(deployPoolTx);
// 0xd3797c5da2cf2db453b995fb8f7a9199f4106ad9

// Deploy gauge

const deployGaugeTx = await curve.stableNgFactory.deployGauge(poolAddress);
// {
// hash: '0x37a53a08d6c71095de8c25bcd4a01b39beec35990f77c7b98355bd064511541f',
// type: 0,
// accessList: null,
// ...
// }

const gaugeAddress = await curve.stableNgFactory.getDeployedGaugeAddress(deployGaugeTx);
// 0x326290a1b0004eee78fa6ed4f1d8f4b2523ab669

//For sidechain
const salt = '15'
//salt - unical random string
const deployGaugeSidechain = await curve.stableNgFactory.deployGaugeSidechain(poolAddress, salt);
// ContractTransactionResponse {
// provider: JsonRpcProvider {},
// blockNumber: 17393463,
// blockHash: '0x7f393493d7eb30b39aeef3118b51925426946eb83b72b18946f0da8c7bec40a0',
// ...
// }
const gaugeSidechainAddress = await curve.stableNgFactory.getDeployedGaugeAddress(deployGaugeSidechain);
// 0x60d3d7ebbc44dc810a743703184f062d00e6db7e
//After that should be deployed mirror gauge on mainnet with same salt
//const gaugeMirrorTx = await curve.stableNgFactory.deployGaugeMirror(sidechainId, salt);
//const deployedGaugeMirrorAddress = await curve.stableNgFactory.getDeployedGaugeMirrorAddressByTx(gaugeMirrorTx);
//OR
//const deployedGaugeMirrorAddress = await curve.stableNgFactory.getDeployedGaugeMirrorAddress(sidechainId);
```
### Deploy crypto pool
Expand Down
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.52.4",
"version": "2.52.5",
"description": "JavaScript library for curve.fi",
"main": "lib/index.js",
"author": "Macket",
Expand Down
2 changes: 1 addition & 1 deletion src/curve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ class Curve implements ICurve {
}

fetchStableNgFactoryPools = async (useApi = true): Promise<void> => {
if (![1, 56, 8453, 42161].includes(this.chainId)) return;
if (this.chainId === 1313161554) return;

if (useApi) {
this.constants.STABLE_NG_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(await getFactoryPoolsDataFromApi.call(this, "factory-stable-ng"));
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,14 @@ const curve = {
getPoolList: _curve.getStableNgFactoryPoolList,
deployPlainPool: deployStableNgPlainPool,
deployMetaPool: deployStableNgMetaPool,
deployGauge: async (poolAddress: string): Promise<ethers.ContractTransactionResponse> => deployGauge(poolAddress, _curve.constants.ALIASES.stable_ng_factory),
deployGaugeSidechain: async (poolAddress: string, salt: string): Promise<ethers.ContractTransactionResponse> => deployGaugeSidechain(poolAddress, salt),
deployGaugeMirror: async (chainId: number, salt: string): Promise<ethers.ContractTransactionResponse> => deployGaugeMirror(chainId, salt),
getDeployedPlainPoolAddress: getDeployedStablePlainPoolAddress,
getDeployedMetaPoolAddress: getDeployedStableMetaPoolAddress,
getDeployedGaugeAddress: getDeployedGaugeAddress,
getDeployedGaugeMirrorAddress: getDeployedGaugeMirrorAddress,
getDeployedGaugeMirrorAddressByTx: getDeployedGaugeMirrorAddressByTx,
fetchRecentlyDeployedPool: _curve.fetchRecentlyDeployedStableNgFactoryPool,
estimateGas: {
deployPlainPool: deployStableNgPlainPoolEstimateGas,
Expand Down
2 changes: 1 addition & 1 deletion src/pools/PoolTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ export class PoolTemplate {

public async depositBonus(amounts: (number | string)[]): Promise<string> {
const amountsBN = amounts.map(BN);
const prices = await this._underlyingPrices();
const prices = (this.isCrypto || this.id === 'wsteth' || this.id === 'factory-crvusd-24') ? await this._underlyingPrices() : this.underlyingCoins.map(() => 1);
const pricesBN = prices.map(BN);
const balancesBN = (await this.stats.underlyingBalances()).map(BN);
const balancedAmounts = this._balancedAmountsWithSameValue(amountsBN, pricesBN, balancesBN);
Expand Down
79 changes: 79 additions & 0 deletions test/readme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,3 +804,82 @@ const deployTricryptoPoolTest = async () => {
const underlyingBalances = await pool.stats.underlyingBalances();
console.log(underlyingBalances);
}

const deployStableNgPlainPool = async () => {
await curve.init('JsonRpc', {}, { gasPrice: 0 });

const coins = [
"0xae7ab96520de3a18e5e111b5eaab095312d7fe84", // stETH
"0xac3e018457b222d93114458476f3e3416abbe38f", // sfrxETH
];

//0 = Standard, 1 = Oracle, 2 = Rebasing, 3 = ERC4626
const assetTypes = [2, 1] as Array<0 | 1 | 2 | 3>;

const oracleAddresses = [
'0x0000000000000000000000000000000000000000',
'0xac3e018457b222d93114458476f3e3416abbe38f',
];

const methodNames = [
'',
'pricePerShare',
];

// Deploy pool

const deployPoolTx = await curve.stableNgFactory.deployPlainPool('Test pool', 'test', coins, 5, 0.05, 5, assetTypes, 0, 600, oracleAddresses, methodNames);

const poolAddress = await curve.stableNgFactory.getDeployedPlainPoolAddress(deployPoolTx);
console.log(poolAddress)
// 0x0816bc9ced716008c88bb8940c297e9c9167755e

// Deploy gauge

if(curve.chainId === 1) {
const deployGaugeTx = await curve.stableNgFactory.deployGauge(poolAddress);

const gaugeAddress = await curve.stableNgFactory.getDeployedGaugeAddress(deployGaugeTx);
console.log(gaugeAddress)
} else {
const salt = '15'

const deployGaugeSidechain = await curve.stableNgFactory.deployGaugeSidechain(poolAddress, salt);

const gaugeSidechainAddress = await curve.stableNgFactory.getDeployedGaugeAddress(deployGaugeSidechain);
console.log(gaugeSidechainAddress)
}

}

const deployStableNgMetaPool = async () => {
await curve.init('JsonRpc', {}, { gasPrice: 0 });

const basePool = "0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7"; // 3pool address
const coin = "0xac3e018457b222d93114458476f3e3416abbe38f"; // sfrxETH
const oracleAddress = '0xac3e018457b222d93114458476f3e3416abbe38f';
const methodName = 'pricePerShare';

// Deploy pool

const deployPoolTx = await curve.stableNgFactory.deployMetaPool(basePool, 'Test pool', 'test', coin, 5, 0.05, 5, 600, 0, 0, methodName, oracleAddress);

const poolAddress = await curve.factory.getDeployedMetaPoolAddress(deployPoolTx);
console.log(poolAddress);

// Deploy gauge

if(curve.chainId === 1) {
const deployGaugeTx = await curve.stableNgFactory.deployGauge(poolAddress);

const gaugeAddress = await curve.stableNgFactory.getDeployedGaugeAddress(deployGaugeTx);
console.log(gaugeAddress);
} else {
const salt = '15'
//salt - unical random string
const deployGaugeSidechain = await curve.stableNgFactory.deployGaugeSidechain(poolAddress, salt);

const gaugeSidechainAddress = await curve.stableNgFactory.getDeployedGaugeAddress(deployGaugeSidechain);
console.log(gaugeSidechainAddress);
}
}

0 comments on commit 3057895

Please sign in to comment.