Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat boosted pool add and remove #450

Merged
merged 43 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
4ba2977
draft: boosted pool adds
mkflow27 Oct 23, 2024
4b0a12a
docs: remove comments.
mkflow27 Oct 23, 2024
6252354
undo mock data return
mkflow27 Oct 27, 2024
3150707
add liquidity boosted
mkflow27 Oct 27, 2024
f2965d0
remove liquidity boosted
mkflow27 Oct 28, 2024
5f3bdd2
Merge branch 'main' into feat-boosted-pool-add-and-remove
mkflow27 Oct 28, 2024
963604f
add/remove boosted
mkflow27 Oct 28, 2024
a92cbe2
undo version
mkflow27 Oct 28, 2024
d63b0f4
Update package.json
mkflow27 Oct 28, 2024
b871178
fix build
mkflow27 Oct 28, 2024
2bd0d05
Merge branch 'feat-boosted-pool-add-and-remove' of https://github.com…
mkflow27 Oct 29, 2024
03a662a
refactor: don't use helpers in tests
mkflow27 Oct 29, 2024
bb1b0e3
docs: remove debug info
mkflow27 Oct 29, 2024
344930f
refactor: change array access
mkflow27 Oct 29, 2024
4cc050f
test: remove unnecessary input
mkflow27 Oct 29, 2024
82e21f5
refactor: allow optional user data but use default values if none pro…
mkflow27 Oct 29, 2024
03e4537
refactor: remove api dependency & update shared poolState
mkflow27 Oct 29, 2024
acae0a2
refactor: harcode data, type refactoring
mkflow27 Oct 29, 2024
c71efcc
chore: lint
mkflow27 Oct 29, 2024
304c4b8
chore: update casing
mkflow27 Oct 29, 2024
325e5a6
test: skip nested tests
mkflow27 Oct 29, 2024
ac966a3
chore: syntax
mkflow27 Oct 29, 2024
4ab2ca3
refactor: return userData in query outputs
mkflow27 Oct 29, 2024
30bad2b
chore: lint
mkflow27 Oct 29, 2024
4782051
first pass input validator
mkflow27 Oct 29, 2024
4eb61ea
handle different input amounts lengths
mkflow27 Oct 30, 2024
e3e1766
chore: rename folder
mkflow27 Oct 30, 2024
b2007f6
docs: remove debugging comment
mkflow27 Oct 30, 2024
a79a673
feat: handle reference amount not pool token
mkflow27 Oct 30, 2024
88b755b
refactor: delete unnecessary additions
mkflow27 Oct 30, 2024
87d7742
fix: remove inaccurate assessment due to getAmounts being used
mkflow27 Oct 30, 2024
30a62d8
feat: expose optional userData arg for buildCall
mkflow27 Oct 30, 2024
8934f9d
feat: userData for remove liq
mkflow27 Oct 30, 2024
2518815
Merge branch 'main' into feat-boosted-pool-add-and-remove
mkflow27 Oct 30, 2024
ee784f5
chore: remove duplicate
mkflow27 Oct 30, 2024
fd9b7c4
chore: lint
mkflow27 Oct 30, 2024
2b615f0
refactor: addLiquidity.
johngrantuk Oct 30, 2024
d3a4091
refactor: removeLiquidity.
johngrantuk Oct 30, 2024
3a5b3ca
refactor: InputValidator.
johngrantuk Oct 30, 2024
f3ede14
fix: access underlyingToken
mkflow27 Oct 30, 2024
c4d8410
style: remove logs
mkflow27 Oct 30, 2024
98734f7
Merge pull request #456 from balancer/feat-boosted-pool-add-and-remov…
mkflow27 Oct 30, 2024
1ce9784
chore: add changeset
mkflow27 Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 177 additions & 0 deletions src/abi/erc4626.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
export const erc4626Abi = [
{
inputs: [
{
internalType: 'address',
name: 'asset',
type: 'address',
},
],
stateMutability: 'nonpayable',
type: 'constructor',
},
{
inputs: [
{
internalType: 'uint256',
name: 'assets',
type: 'uint256',
},
],
name: 'deposit',
outputs: [
{
internalType: 'uint256',
name: 'shares',
type: 'uint256',
},
],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: 'uint256',
name: 'shares',
type: 'uint256',
},
],
name: 'withdraw',
outputs: [
{
internalType: 'uint256',
name: 'assets',
type: 'uint256',
},
],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [],
name: 'asset',
outputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'uint256',
name: 'assets',
type: 'uint256',
},
],
name: 'convertToShares',
outputs: [
{
internalType: 'uint256',
name: 'shares',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'uint256',
name: 'shares',
type: 'uint256',
},
],
name: 'convertToAssets',
outputs: [
{
internalType: 'uint256',
name: 'assets',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'totalAssets',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'caller',
type: 'address',
},
{
indexed: true,
internalType: 'address',
name: 'owner',
type: 'address',
},
{
indexed: false,
internalType: 'uint256',
name: 'assets',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint256',
name: 'shares',
type: 'uint256',
},
],
name: 'Deposit',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'caller',
type: 'address',
},
{
indexed: true,
internalType: 'address',
name: 'receiver',
type: 'address',
},
{
indexed: false,
internalType: 'uint256',
name: 'assets',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint256',
name: 'shares',
type: 'uint256',
},
],
name: 'Withdraw',
type: 'event',
},
];
1 change: 1 addition & 0 deletions src/abi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from './weightedPool.V3';
export * from './vaultAdmin.V3';
export * from './stablePoolFactory.V3';
export * from './balancerCompositeLiquidityRouter';
export * from './erc4626';
49 changes: 48 additions & 1 deletion src/data/providers/balancer-api/modules/pool-state/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { BalancerApiClient } from '../../client';
import { PoolState, PoolStateWithBalances } from '../../../../../entities';
import {
PoolState,
PoolStateWithBalances,
PoolStateWithUnderlyings,
} from '../../../../../entities';
import { mapPoolType } from '../../../../../utils/poolTypeMapper';

import { API_CHAIN_NAMES } from '../../../../../utils/constants';
Expand Down Expand Up @@ -39,6 +43,29 @@ export class Pools {
}
}`;

readonly boostedPoolStateWithUnderlying = `
query GetPool($id: String!, $chain: GqlChain!) {
poolGetPool(id:$id, chain:$chain) {
id
address
type
protocolVersion
poolTokens {
index
address
decimals
balance
underlyingToken {
address
decimals
}
}
dynamicData {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I think I can actually remove the changes in the api, since I am not using the api in my tests, as we decided to use mock data. I'll remove it.

totalShares
}
}
}`;

constructor(private readonly balancerApiClient: BalancerApiClient) {}

async fetchPoolState(id: string): Promise<PoolState> {
Expand Down Expand Up @@ -76,4 +103,24 @@ export class Pools {
};
return poolStateWithBalances;
}

async fetchPoolStateWithUnderlyingTokens(
id: string,
): Promise<PoolStateWithUnderlyings> {
const { data } = await this.balancerApiClient.fetch({
query: this.boostedPoolStateWithUnderlying,
variables: {
id: id.toLowerCase(),
chain: API_CHAIN_NAMES[this.balancerApiClient.chainId],
},
});
const poolStateWithUnderlyings: PoolStateWithUnderlyings = {
...data.poolGetPool,
tokens: data.poolGetPool.poolTokens,
type: mapPoolType(data.poolGetPool.type),
//underlyings: data.poolGetPool.poolTokens.map((token) => {token}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

totalShares: data.poolGetPool.dynamicData.totalShares,
};
return poolStateWithUnderlyings;
}
}
4 changes: 4 additions & 0 deletions src/data/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ export interface MinimalToken {
export interface PoolTokenWithBalance extends MinimalToken {
balance: HumanAmount;
}

export interface PoolTokenWithUnderlying extends MinimalToken {
underlying: Address;
}
31 changes: 31 additions & 0 deletions src/entities/addLiquidityBoosted/doAddLiquidityPropotionalQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { createPublicClient, http, getAddress } from 'viem';

import { BALANCER_COMPOSITE_LIQUIDITY_ROUTER, CHAINS } from '@/utils';

import { AddLiquidityProportionalInput } from '../addLiquidity/types';
import { Address } from '@/types';

import { balancerCompositeLiquidityRouterAbi } from '@/abi';

export const doAddLiquidityProportionalQuery = async (
{ rpcUrl, chainId, referenceAmount }: AddLiquidityProportionalInput,
johngrantuk marked this conversation as resolved.
Show resolved Hide resolved
poolAddress: Address,
): Promise<bigint[]> => {
const client = createPublicClient({
transport: http(rpcUrl),
chain: CHAINS[chainId],
});

const { result: exactAmountsIn } = await client.simulateContract({
address: BALANCER_COMPOSITE_LIQUIDITY_ROUTER[chainId],
abi: balancerCompositeLiquidityRouterAbi,
functionName: 'queryAddLiquidityProportionalToERC4626Pool',
args: [
poolAddress,
referenceAmount.rawAmount,
getAddress('0xa5cc3c03994db5b0d9a5eEdD10Cabab0813678ac'),
'0x',
],
});
return [...exactAmountsIn];
};
31 changes: 31 additions & 0 deletions src/entities/addLiquidityBoosted/doAddLiquidityUnbalancedQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { createPublicClient, http, getAddress } from 'viem';

import { BALANCER_COMPOSITE_LIQUIDITY_ROUTER, CHAINS } from '@/utils';

import { AddLiquidityUnbalancedInput } from '../addLiquidity/types';
import { Address } from '@/types';

import { balancerCompositeLiquidityRouterAbi } from '@/abi';

export const doAddLiquidityUnbalancedQuery = async (
{ rpcUrl, chainId, amountsIn }: AddLiquidityUnbalancedInput,
johngrantuk marked this conversation as resolved.
Show resolved Hide resolved
poolAddress: Address,
): Promise<bigint> => {
const client = createPublicClient({
transport: http(rpcUrl),
chain: CHAINS[chainId],
});

const { result: bptAmountOut } = await client.simulateContract({
address: BALANCER_COMPOSITE_LIQUIDITY_ROUTER[chainId],
abi: balancerCompositeLiquidityRouterAbi,
functionName: 'queryAddLiquidityUnbalancedToERC4626Pool',
args: [
poolAddress,
amountsIn.map((input) => input.rawAmount),
getAddress('0xa5cc3c03994db5b0d9a5eEdD10Cabab0813678ac'),
'0x',
],
});
return bptAmountOut;
};
Loading
Loading