Skip to content

Commit

Permalink
Merge pull request #537 from beethovenxfi/feature/composableType
Browse files Browse the repository at this point in the history
Feature/composable type
  • Loading branch information
franzns authored Dec 19, 2023
2 parents 9915939 + c871c54 commit 5b932f6
Show file tree
Hide file tree
Showing 21 changed files with 103 additions and 189 deletions.
12 changes: 0 additions & 12 deletions modules/network/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,6 @@ const arbitrumNetworkData: NetworkData = {
},
balancer: {
vault: '0xba12222222228d8ba445958a75a0704d566bf2c8',
composableStablePoolFactories: [
'0xaeb406b0e430bf5ea2dc0b9fe62e4e53f74b3a33',
'0x85a80afee867adf27b50bdb7b76da70f1e853062',
'0x1c99324edc771c82a0dccb780cc7dda0045e50e7',
'0x2498a2b0d6462d2260eac50ae1c3e03f4829ba95',
'0xa8920455934da4d853faac1f94fe7bef72943ef1',
],
weightedPoolV2Factories: [
'0x8df6efec5547e31b0eb7d1291b511ff8a2bf987c',
'0xf1665e19bc105be4edd3739f88315cc699cc5b65',
'0xc7e5ed1054a24ef31d827e6f86caa58b3bc168d7',
],
swapProtocolFeePercentage: 0.5,
yieldProtocolFeePercentage: 0.5,
},
Expand Down
8 changes: 0 additions & 8 deletions modules/network/avalanche.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ const avalancheNetworkData: NetworkData = {
},
balancer: {
vault: '0xba12222222228d8ba445958a75a0704d566bf2c8',
composableStablePoolFactories: [
'0x3b1eb8eb7b43882b385ab30533d9a2bef9052a98',
'0xe42ffa682a26ef8f25891db4882932711d42e467',
],
weightedPoolV2Factories: [
'0x94f68b54191f62f781fe8298a8a5fa3ed772d227',
'0x230a59f4d9adc147480f03b0d3fffecd56c3289a',
],
swapProtocolFeePercentage: 0.5,
yieldProtocolFeePercentage: 0.5,
},
Expand Down
2 changes: 0 additions & 2 deletions modules/network/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ const baseNetworkData: NetworkData = {
},
balancer: {
vault: '0xba12222222228d8ba445958a75a0704d566bf2c8',
composableStablePoolFactories: ['0x8df317a729fcaa260306d7de28888932cb579b88'],
weightedPoolV2Factories: ['0x4c32a8a8fda4e24139b51b456b42290f51d6a1c4'],
swapProtocolFeePercentage: 0.5,
yieldProtocolFeePercentage: 0.5,
},
Expand Down
19 changes: 0 additions & 19 deletions modules/network/fantom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,8 @@ const fantomNetworkData: NetworkData = {
},
balancer: {
vault: '0x20dd72ed959b6147912c2e529f0a0c651c33c9ce',
composableStablePoolFactories: [
'0x5adaf6509bcec3219455348ac45d6d3261b1a990',
'0xb384a86f2fd7788720db42f9daa60fc07ecbea06',
'0x44814e3a603bb7f1198617995c5696c232f6e8ed',
'0x911566c808bf00acb200b418564440a2af177548',
'0x5c3094982cf3c97a06b7d62a6f7669f14a199b19',
'0x23f03a4fb344d8b98833d2ace093cc305e03474f',
],
weightedPoolV2Factories: [
'0xb2ed595afc445b47db7043bec25e772bf0fa1fbb',
'0x8ea1c497c16726e097f62c8c9fbd944143f27090',
'0xea87f3dffc679035653c0fba70e7bfe46e3fb733',
'0xd678b6acd834cc969bb19ce82727f2a541fb7941',
'0xb841df73861e65e6d61a80f503f095a91ce75e15',
],
swapProtocolFeePercentage: 0.25,
yieldProtocolFeePercentage: 0.25,
factoriesWithpoolSpecificProtocolFeePercentagesProvider: [
'0xb841df73861e65e6d61a80f503f095a91ce75e15',
'0x5c3094982cf3c97a06b7d62a6f7669f14a199b19',
],
},
multicall: '0x66335d7ad8011f6aa3f48aadcb523b62b38ed961',
multicall3: '0xca11bde05977b3631167028862be2a173976ca11',
Expand Down
11 changes: 0 additions & 11 deletions modules/network/gnosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@ const gnosisNetworkData: NetworkData = {
},
balancer: {
vault: '0xba12222222228d8ba445958a75a0704d566bf2c8',
composableStablePoolFactories: [
'0x76578ecf9a141296ec657847fb45b0585bcda3a6',
'0xc128468b7ce63ea702c1f104d55a2566b13d3abd',
'0xd87f44df0159dc78029ab9ca7d7e57e7249f5acd',
'0x4bdcc2fb18aeb9e2d281b0278d946445070eada7',
],
weightedPoolV2Factories: [
'0x6cad2ea22bfa7f4c14aae92e47f510cd5c509bc7',
'0xf302f9f50958c5593770fdf4d4812309ff77414f',
'0xc128a9954e6c874ea3d62ce62b468ba073093f25',
],
swapProtocolFeePercentage: 0.5,
yieldProtocolFeePercentage: 0.5,
},
Expand Down
14 changes: 0 additions & 14 deletions modules/network/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,8 @@ const data: NetworkData = {
balancer: {
vault: '0xba12222222228d8ba445958a75a0704d566bf2c8',
tokenAdmin: '0xf302f9f50958c5593770fdf4d4812309ff77414f',
composableStablePoolFactories: [
'0xf9ac7b9df2b3454e841110cce5550bd5ac6f875f',
'0x85a80afee867adf27b50bdb7b76da70f1e853062',
'0xdba127fbc23fb20f5929c546af220a991b5c6e01',
'0xfada0f4547ab2de89d1304a668c39b3e09aa7c76',
'0xdb8d758bcb971e482b2c45f7f8a7740283a1bd3a',
'0xba1b4a90bad57470a2cba762a32955dc491f76e0',
],
weightedPoolV2Factories: [
'0xcc508a455f5b0073973107db6a878ddbdab957bc',
'0x5dd94da3644ddd055fcf6b3e1aa310bb7801eb8b',
'0x897888115ada5773e02aa29f775430bfb5f34c51',
],
swapProtocolFeePercentage: 0.5,
yieldProtocolFeePercentage: 0.5,
excludedPoolDataQueryPoolIds: ['0xf71d0774b214c4cf51e33eb3d30ef98132e4dbaa00000000000000000000046e'],
},
multicall: '0x5ba1e12693dc8f9c48aad8770482f4739beed696',
multicall3: '0xca11bde05977b3631167028862be2a173976ca11',
Expand Down
4 changes: 0 additions & 4 deletions modules/network/network-config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,8 @@ export interface NetworkData {
balancer: {
vault: string;
tokenAdmin?: string;
weightedPoolV2Factories: string[];
composableStablePoolFactories: string[];
yieldProtocolFeePercentage: number;
swapProtocolFeePercentage: number;
excludedPoolDataQueryPoolIds?: string[];
factoriesWithpoolSpecificProtocolFeePercentagesProvider?: string[];
};
multicall: string;
multicall3: string;
Expand Down
16 changes: 4 additions & 12 deletions modules/network/optimism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ const optimismNetworkData: NetworkData = {
},
balancer: {
vault: '0xba12222222228d8ba445958a75a0704d566bf2c8',
composableStablePoolFactories: [
'0xf145cafb67081895ee80eb7c04a30cf87f07b745',
'0xe2e901ab09f37884ba31622df3ca7fc19aa443be',
'0x1802953277fd955f9a254b80aa0582f193cf1d77',
'0x043a2dad730d585c44fb79d2614f295d2d625412',
],
weightedPoolV2Factories: [
'0xad901309d9e9dbc5df19c84f729f429f0189a633',
'0xa0dabebaad1b243bbb243f933013d560819eb66f',
'0x230a59f4d9adc147480f03b0d3fffecd56c3289a',
],
swapProtocolFeePercentage: 0.5,
yieldProtocolFeePercentage: 0.5,
},
Expand Down Expand Up @@ -298,7 +287,10 @@ export const optimismNetworkConfig: NetworkConfig = {
],
userStakedBalanceServices: [new UserSyncGaugeBalanceService()],
services: {
balancerSubgraphService: new BalancerSubgraphService(optimismNetworkData.subgraphs.balancer, optimismNetworkData.chain.id),
balancerSubgraphService: new BalancerSubgraphService(
optimismNetworkData.subgraphs.balancer,
optimismNetworkData.chain.id,
),
},
/*
For sub-minute jobs we set the alarmEvaluationPeriod and alarmDatapointsToAlarm to 1 instead of the default 3.
Expand Down
12 changes: 0 additions & 12 deletions modules/network/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,6 @@ const polygonNetworkData: NetworkData = {
},
balancer: {
vault: '0xba12222222228d8ba445958a75a0704d566bf2c8',
composableStablePoolFactories: [
'0x136fd06fa01ecf624c7f2b3cb15742c1339dc2c4',
'0x85a80afee867adf27b50bdb7b76da70f1e853062',
'0x7bc6c0e73edaa66ef3f6e2f27b0ee8661834c6c9',
'0x6ab5549bbd766a43afb687776ad8466f8b42f777',
'0xe2fa4e1d17725e72dcdafe943ecf45df4b9e285b',
],
weightedPoolV2Factories: [
'0x0e39c3d9b2ec765efd9c5c70bb290b1fcd8536e3',
'0x82e4cfaef85b1b6299935340c964c942280327f4',
'0xfc8a407bba312ac761d8bfe04ce1201904842b76',
],
swapProtocolFeePercentage: 0.5,
yieldProtocolFeePercentage: 0.5,
},
Expand Down
6 changes: 0 additions & 6 deletions modules/network/zkevm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ const zkevmNetworkData: NetworkData = {
},
balancer: {
vault: '0xba12222222228d8ba445958a75a0704d566bf2c8',
composableStablePoolFactories: [
'0x8ea89804145c007e7d226001a96955ad53836087',
'0x956ccab09898c0af2aca5e6c229c3ad4e93d9288',
'0x577e5993b9cc480f07f98b5ebd055604bd9071c4',
],
weightedPoolV2Factories: ['0x03f3fb107e74f2eac9358862e91ad3c692712054'],
swapProtocolFeePercentage: 0.5,
yieldProtocolFeePercentage: 0.5,
},
Expand Down
67 changes: 56 additions & 11 deletions modules/pool/lib/pool-creator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ export class PoolCreatorService {
const nestedPool = subgraphPools.find((nestedPool) => {
const poolType = this.mapSubgraphPoolTypeToPoolType(nestedPool.poolType || '');

return nestedPool.address === token.address && (poolType === 'LINEAR' || poolType === 'PHANTOM_STABLE');
return (
nestedPool.address === token.address && (poolType === 'LINEAR' || poolType === 'COMPOSABLE_STABLE')
);
});

if (nestedPool) {
Expand Down Expand Up @@ -197,7 +199,7 @@ export class PoolCreatorService {
const allNestedTypePools = await prisma.prismaPool.findMany({
where: {
chain: this.chain,
type: { in: [PrismaPoolType.LINEAR, PrismaPoolType.PHANTOM_STABLE] },
type: { in: [PrismaPoolType.LINEAR, PrismaPoolType.COMPOSABLE_STABLE] },
},
select: { id: true, address: true },
});
Expand All @@ -222,6 +224,12 @@ export class PoolCreatorService {
],
});

// for the old phantom stable pool, we add it to the DB as type COMPOSABLE_STABLE with version 0
let poolTypeVersion = pool.poolTypeVersion ? pool.poolTypeVersion : 1;
if (pool.poolType === 'StablePhantom') {
poolTypeVersion = 0;
}

await prisma.prismaPool.create({
data: {
id: pool.id,
Expand All @@ -232,7 +240,7 @@ export class PoolCreatorService {
name: pool.name || '',
decimals: 18,
type: poolType,
version: pool.poolTypeVersion ? pool.poolTypeVersion : 1,
version: poolTypeVersion,
owner: pool.owner || ZERO_ADDRESS,
factory: pool.factory,
tokens: {
Expand Down Expand Up @@ -308,7 +316,7 @@ export class PoolCreatorService {
}
: undefined,
stableDynamicData:
poolType === 'STABLE' || poolType === 'PHANTOM_STABLE' || poolType === 'META_STABLE'
poolType === 'STABLE' || poolType === 'COMPOSABLE_STABLE' || poolType === 'META_STABLE'
? {
create: {
id: pool.id,
Expand Down Expand Up @@ -410,26 +418,62 @@ export class PoolCreatorService {
}
}

public async updatePoolTypesAndVersionForAllPools() {
const subgraphPools = await this.balancerSubgraphService.getAllPools({}, false);

for (const subgraphPool of subgraphPools) {
// for the old phantom stable pool, we add it to the DB as type COMPOSABLE_STABLE with version 0
let poolTypeVersion = subgraphPool.poolTypeVersion ? subgraphPool.poolTypeVersion : 1;
if (subgraphPool.poolType === 'StablePhantom') {
poolTypeVersion = 0;
}

const poolType = this.mapSubgraphPoolTypeToPoolType(subgraphPool.poolType || '');

try {
await prisma.prismaPool.update({
where: { id_chain: { chain: networkContext.chain, id: subgraphPool.id } },
data: {
version: poolTypeVersion,
type: poolType,
},
});
} catch (e: any) {
// Some pools are filtered from the DB, like test pools,
// so we just ignore them without breaking the loop
const error = e.meta ? e.meta.cause : e;
console.error(
'Error in updating pool versions: ',
error,
'Network',
networkContext.chain,
'Pool ID: ',
subgraphPool.id,
);
}
}
}

private sortSubgraphPools(subgraphPools: BalancerPoolFragment[]) {
return _.sortBy(subgraphPools, (pool) => {
const poolType = this.mapSubgraphPoolTypeToPoolType(pool.poolType || '');

if (poolType === 'LINEAR') {
return 0;
} else if (poolType === 'PHANTOM_STABLE') {
//if the phantom stable has a nested phantom stable, it needs to appear later in the list
const nestedPhantomStableToken = (pool.tokens || []).find((token) => {
} else if (poolType === 'COMPOSABLE_STABLE') {
//if the composable stable has a nested composable stable, it needs to appear later in the list
const nestedComposableStableToken = (pool.tokens || []).find((token) => {
if (token.address === pool.address) {
return false;
}

const nestedPool = subgraphPools.find((nestedPool) => nestedPool.address === token.address);
const nestedPoolType = this.mapSubgraphPoolTypeToPoolType(nestedPool?.poolType || '');

return nestedPoolType === 'PHANTOM_STABLE';
return nestedPoolType === 'COMPOSABLE_STABLE';
});

return nestedPhantomStableToken ? 2 : 1;
return nestedComposableStableToken ? 2 : 1;
}

return 3;
Expand All @@ -446,10 +490,11 @@ export class PoolCreatorService {
return 'STABLE';
case 'MetaStable':
return 'META_STABLE';
// for the old phantom stable pool, we add it to the DB as type COMPOSABLE_STABLE with version 0
case 'StablePhantom':
return 'PHANTOM_STABLE';
return 'COMPOSABLE_STABLE';
case 'ComposableStable':
return 'PHANTOM_STABLE';
return 'COMPOSABLE_STABLE';
case 'Linear':
return 'LINEAR';
case 'Element':
Expand Down
Loading

0 comments on commit 5b932f6

Please sign in to comment.