Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into change-contract-positions-for-kwenta-and-pol…
Browse files Browse the repository at this point in the history
…ynomial
  • Loading branch information
immasandwich authored Dec 11, 2023
2 parents 77bc9c6 + 954d23c commit 20625f1
Show file tree
Hide file tree
Showing 37 changed files with 2,731 additions and 514 deletions.
47 changes: 47 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,53 @@

[1]: https://www.npmjs.com/package/@zapper-fi/studio?activeTab=versions

## [0.563.0](https://github.com/Zapper-fi/studio/compare/v0.562.2...v0.563.0) (2023-12-11)


### Features

* **dhedge-v2:** Add staking position ([#3125](https://github.com/Zapper-fi/studio/issues/3125)) ([74580db](https://github.com/Zapper-fi/studio/commit/74580dba5037512450ba049a64be36a787e6343a))

## [0.562.2](https://github.com/Zapper-fi/studio/compare/v0.562.1...v0.562.2) (2023-12-11)


### Bug Fixes

* **pickle:** Fix Jars without getRatio method ([#3124](https://github.com/Zapper-fi/studio/issues/3124)) ([81bf3af](https://github.com/Zapper-fi/studio/commit/81bf3af3b15b4c9b205c53e72a23fc301bf5bd4d))

## [0.562.1](https://github.com/Zapper-fi/studio/compare/v0.562.0...v0.562.1) (2023-12-11)


### Bug Fixes

* **reaper:** Fix vault definitions ([#3122](https://github.com/Zapper-fi/studio/issues/3122)) ([ef9d1d9](https://github.com/Zapper-fi/studio/commit/ef9d1d9b6dcf771c9597b37b0e52dd0453fe7e1a))

## [0.562.0](https://github.com/Zapper-fi/studio/compare/v0.561.0...v0.562.0) (2023-12-11)


### Features

* **studio:** Eliminate dependencies on subgraphs for volume ([#3120](https://github.com/Zapper-fi/studio/issues/3120)) ([731d200](https://github.com/Zapper-fi/studio/commit/731d200bf54e43d3d4246b5410d4836cd6cf4944))

## [0.561.0](https://github.com/Zapper-fi/studio/compare/v0.560.0...v0.561.0) (2023-12-10)


### Features

* **abracadabra:** Add support for GM cauldrons on Arbitrum ([#3117](https://github.com/Zapper-fi/studio/issues/3117)) ([267512b](https://github.com/Zapper-fi/studio/commit/267512b06335f1dabbced95b68ce20d3e74c69a2))


### Bug Fixes

* **pickle:** Fix jars definitions ([#3118](https://github.com/Zapper-fi/studio/issues/3118)) ([37df230](https://github.com/Zapper-fi/studio/commit/37df230d6bd313619fbcf66e608f90917e864503))

## [0.560.0](https://github.com/Zapper-fi/studio/compare/v0.559.4...v0.560.0) (2023-12-09)


### Features

* **uniswap-v2:** Remove optimization for Uniswap pool token balances ([721b18e](https://github.com/Zapper-fi/studio/commit/721b18e17d9d6275f3387308a3674e3a29eea79a))

## [0.559.4](https://github.com/Zapper-fi/studio/compare/v0.559.3...v0.559.4) (2023-12-09)


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": "@zapper-fi/studio",
"version": "0.559.4",
"version": "0.563.0",
"description": "Community build apps for Zapper.fi",
"license": "MIT",
"main": "./index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export const ARBITRUM_CAULDRONS: AbracadabraCauldronContractPositionDefinition[]
{ version: 'V2', type: 'REGULAR', address: '0xc89958b03a55b5de2221acb25b58b89a000215e6' }, // wETH
{ version: 'V4', type: 'GLP', address: '0x5698135ca439f21a57bddbe8b582c62f090406d5' }, // GLP
{ version: 'V4', type: 'REGULAR', address: '0x726413d7402ff180609d0ebc79506df8633701b1' }, // magicGLP
{ version: 'V4', type: 'REGULAR', address: '0x4F9737E994da9811B8830775Fd73E2F1C8e40741' }, // gmARB
{ version: 'V4', type: 'REGULAR', address: '0xD7659D913430945600dfe875434B6d80646d552A' }, // gmBTC
{ version: 'V4', type: 'REGULAR', address: '0x2b02bBeAb8eCAb792d3F4DDA7a76f63Aa21934FA' }, // gmETH
{ version: 'V4', type: 'REGULAR', address: '0x7962ACFcfc2ccEBC810045391D60040F635404fb' }, // gmSOL
];

export const ARBITRUM_GLP_TOKEN_ADDRESS = '0x4277f8f2c384827b5273592ff7cebd9f2c1ac258';
Expand Down
7 changes: 1 addition & 6 deletions src/apps/balancer-v1/balancer-v1.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ import { AbstractApp } from '~app/app.dynamic-module';

import { BalancerV1ViemContractFactory } from './contracts';
import { EthereumBalancerV1PoolTokenFetcher } from './ethereum/balancer-v1.pool.token-fetcher';
import { EthereumBalancerV1PoolSubgraphVolumeDataLoader } from './ethereum/balancer-v1.volume.data-loader';

@Module({
providers: [
BalancerV1ViemContractFactory,
EthereumBalancerV1PoolTokenFetcher,
EthereumBalancerV1PoolSubgraphVolumeDataLoader,
],
providers: [BalancerV1ViemContractFactory, EthereumBalancerV1PoolTokenFetcher],
})
export class BalancerV1AppModule extends AbstractApp() {}
58 changes: 0 additions & 58 deletions src/apps/balancer-v1/common/balancer-v1.volume.data-loader.ts

This file was deleted.

23 changes: 1 addition & 22 deletions src/apps/balancer-v1/ethereum/balancer-v1.pool.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Inject } from '@nestjs/common';
import DataLoader from 'dataloader';
import { gql } from 'graphql-request';
import { sum } from 'lodash';

Expand All @@ -25,8 +24,6 @@ import {
import { BalancerV1ViemContractFactory } from '../contracts';
import { BalancerPoolToken } from '../contracts/viem';

import { EthereumBalancerV1PoolSubgraphVolumeDataLoader } from './balancer-v1.volume.data-loader';

type GetAllPoolsData = {
pools: {
id: string;
Expand Down Expand Up @@ -54,13 +51,9 @@ export class EthereumBalancerV1PoolTokenFetcher extends AppTokenTemplatePosition
> {
groupLabel = 'Pools';

volumeDataLoader: DataLoader<string, number>;

constructor(
@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit,
@Inject(BalancerV1ViemContractFactory) protected readonly contractFactory: BalancerV1ViemContractFactory,
@Inject(EthereumBalancerV1PoolSubgraphVolumeDataLoader)
protected readonly volumeDataLoaderBuilder: EthereumBalancerV1PoolSubgraphVolumeDataLoader,
) {
super(appToolkit);
}
Expand All @@ -70,8 +63,6 @@ export class EthereumBalancerV1PoolTokenFetcher extends AppTokenTemplatePosition
}

async getAddresses() {
this.volumeDataLoader = this.volumeDataLoaderBuilder.getLoader();

const poolsFromSubgraph = await gqlFetch<GetAllPoolsData>({
endpoint: 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer?source=zapper',
query: getPoolsQuery,
Expand Down Expand Up @@ -103,26 +94,15 @@ export class EthereumBalancerV1PoolTokenFetcher extends AppTokenTemplatePosition
return liquidity;
}

async getApy({ appToken, contract }: GetDataPropsParams<BalancerPoolToken>) {
const fee = (Number(await contract.read.getSwapFee()) / 10 ** 18) * 100;
const volume = await this.volumeDataLoader.load(appToken.address);
const yearlyFees = volume * fee * 365;
const reserves = (appToken.pricePerShare as number[]).map(pps => pps * appToken.supply);
const liquidity = sum(reserves.map((r, i) => r * appToken.tokens[i].price));
const apy = yearlyFees / liquidity;
return apy;
}

async getDataProps(params: GetDataPropsParams<BalancerPoolToken>) {
const defaultDataProps = await super.getDataProps(params);

const { appToken, contract } = params;
const fee = (Number(await contract.read.getSwapFee()) / 10 ** 18) * 100;
const weightsRaw = await Promise.all(appToken.tokens.map(t => contract.read.getNormalizedWeight([t.address])));
const weight = weightsRaw.map(w => Number(w) / 10 ** 18);
const volume = await this.volumeDataLoader.load(appToken.address);

return { ...defaultDataProps, fee, volume, weight };
return { ...defaultDataProps, fee, weight };
}

async getLabel({
Expand All @@ -143,7 +123,6 @@ export class EthereumBalancerV1PoolTokenFetcher extends AppTokenTemplatePosition
return [
{ label: 'Liquidity', value: buildDollarDisplayItem(appToken.dataProps.liquidity) },
{ label: 'Supply', value: buildNumberDisplayItem(appToken.supply) },
{ label: 'Volume', value: buildDollarDisplayItem(appToken.dataProps.volume) },
{ label: 'Fee', value: buildPercentageDisplayItem(appToken.dataProps.fee) },
{ label: 'Ratio', value: appToken.dataProps.weight.map(p => `${Math.round(p * 100)}%`).join(' / ') },
];
Expand Down
11 changes: 0 additions & 11 deletions src/apps/balancer-v1/ethereum/balancer-v1.volume.data-loader.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ import { CurveFactoryCryptoPoolTokenFetcher } from '../common/curve.factory-cryp
export class BaseCurveFactoryCryptoPoolTokenFetcher extends CurveFactoryCryptoPoolTokenFetcher {
groupLabel = 'Pools';
registryAddress = '0x5ef72230578b3e399e6c6f4f6360edf95e83bbfd';

skipVolume = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ import { CurveFactoryStablePoolTokenFetcher } from '../common/curve.factory-stab
export class BaseCurveFactoryStablePoolTokenFetcher extends CurveFactoryStablePoolTokenFetcher {
groupLabel = 'Pools';
registryAddress = '0x3093f9b57a428f3eb6285a589cb35bea6e78c336';

skipVolume = true;
}
2 changes: 0 additions & 2 deletions src/apps/curve/base/curve.tricrypto-pool.token-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ import { CurveFactoryV2PoolTokenFetcher } from '../common/curve.factory-pool-v2.
export class BaseCurveTricryptoPoolTokenFetcher extends CurveFactoryV2PoolTokenFetcher {
groupLabel = 'Pools';
factoryAddress = '0xa5961898870943c68037f6848d2d866ed2016bcb';

skipVolume = true;
}
26 changes: 4 additions & 22 deletions src/apps/curve/common/curve.pool-dynamic-v2.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Inject } from '@nestjs/common';
import DataLoader from 'dataloader';
import { BigNumberish } from 'ethers';
import { compact, range } from 'lodash';
import { Abi, GetContractReturnType, PublicClient } from 'viem';
Expand Down Expand Up @@ -61,13 +60,9 @@ export abstract class CurvePoolDynamicV2TokenFetcher<T extends Abi> extends AppT
CurveTricryptoPool,
CurvePoolTokenDataProps
> {
volumeDataLoader: DataLoader<string, number>;

abstract factoryAddress: string;
blacklistedTokenAddresses: string[] = [];

skipVolume = false;

abstract resolveFactory(address: string): GetContractReturnType<T, PublicClient>;
abstract resolvePoolCount(params: ResolvePoolCountParams<T>): Promise<BigNumberish>;
abstract resolveTokenAddress(params: ResolveTokenAddressParams<T>): Promise<string>;
Expand All @@ -87,10 +82,6 @@ export abstract class CurvePoolDynamicV2TokenFetcher<T extends Abi> extends AppT
}

async getDefinitions({ multicall }: GetDefinitionsParams) {
if (!this.skipVolume) {
this.volumeDataLoader = this.curveVolumeDataLoader.getLoader({ network: this.network });
}

const contract = multicall.wrap(this.resolveFactory(this.factoryAddress));
const poolCount = await this.resolvePoolCount({ contract, multicall });
const poolRange = range(0, Number(poolCount));
Expand Down Expand Up @@ -143,20 +134,11 @@ export abstract class CurvePoolDynamicV2TokenFetcher<T extends Abi> extends AppT
async getDataProps(params: GetDataPropsParams<CurveTricryptoPool, CurvePoolTokenDataProps>) {
const defaultDataProps = await super.getDataProps(params);

const { contract, definition } = params;
let fee: number;

try {
const fees = await contract.read.fee();
fee = Number(fees) / 10 ** 8;
} catch {
fee = 0;
}
const volume = this.skipVolume == false ? await this.volumeDataLoader.load(definition.address) : 0;
const feeVolume = fee * volume;
const apy = defaultDataProps.liquidity > 0 ? (feeVolume / defaultDataProps.liquidity) * 365 : 0;
const { contract } = params;
const feeRaw = await contract.read.fee().catch(() => 0);
const fee = Number(feeRaw) / 10 ** 10;

return { ...defaultDataProps, fee, volume, apy };
return { ...defaultDataProps, fee };
}

async getLabel({ appToken }: GetDisplayPropsParams<CurveTricryptoPool, CurvePoolTokenDataProps>) {
Expand Down
15 changes: 1 addition & 14 deletions src/apps/curve/common/curve.pool-dynamic.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Inject } from '@nestjs/common';
import DataLoader from 'dataloader';
import { BigNumberish } from 'ethers';
import { compact, range } from 'lodash';
import { Abi, GetContractReturnType, PublicClient } from 'viem';
Expand Down Expand Up @@ -80,13 +79,9 @@ export abstract class CurvePoolDynamicTokenFetcher<T extends Abi> extends AppTok
CurvePoolTokenDataProps,
CurvePoolDefinition
> {
volumeDataLoader: DataLoader<string, number>;

abstract registryAddress: string;
blacklistedSwapAddresses: string[] = [];

skipVolume = false;

abstract resolveRegistry(address: string): GetContractReturnType<T, PublicClient>;
abstract resolvePoolCount(params: ResolvePoolCountParams<T>): Promise<BigNumberish>;
abstract resolveSwapAddress(params: ResolveSwapAddressParams<T>): Promise<string>;
Expand All @@ -108,10 +103,6 @@ export abstract class CurvePoolDynamicTokenFetcher<T extends Abi> extends AppTok
}

async getDefinitions({ multicall }: GetDefinitionsParams) {
if (!this.skipVolume) {
this.volumeDataLoader = this.curveVolumeDataLoader.getLoader({ network: this.network });
}

const contract = multicall.wrap(this.resolveRegistry(this.registryAddress));
const poolCount = await this.resolvePoolCount({ contract, multicall });
const poolRange = range(0, Number(poolCount));
Expand Down Expand Up @@ -175,11 +166,7 @@ export abstract class CurvePoolDynamicTokenFetcher<T extends Abi> extends AppTok
const fees = await this.resolveFees({ contract, swapAddress, multicall });
const fee = Number(fees[0]) / 10 ** 8;

const volume = this.skipVolume == false ? await this.volumeDataLoader.load(definition.swapAddress) : 0;
const feeVolume = fee * volume;
const apy = defaultDataProps.liquidity > 0 ? (feeVolume / defaultDataProps.liquidity) * 365 : 0;

return { ...defaultDataProps, fee, volume, apy, swapAddress };
return { ...defaultDataProps, fee, swapAddress };
}

async getLabel({ appToken }: GetDisplayPropsParams<Erc20, CurvePoolTokenDataProps, CurvePoolDefinition>) {
Expand Down
Loading

0 comments on commit 20625f1

Please sign in to comment.