-
Notifications
You must be signed in to change notification settings - Fork 9
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
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 4b0a12a
docs: remove comments.
mkflow27 6252354
undo mock data return
mkflow27 3150707
add liquidity boosted
mkflow27 f2965d0
remove liquidity boosted
mkflow27 5f3bdd2
Merge branch 'main' into feat-boosted-pool-add-and-remove
mkflow27 963604f
add/remove boosted
mkflow27 a92cbe2
undo version
mkflow27 d63b0f4
Update package.json
mkflow27 b871178
fix build
mkflow27 2bd0d05
Merge branch 'feat-boosted-pool-add-and-remove' of https://github.com…
mkflow27 03a662a
refactor: don't use helpers in tests
mkflow27 bb1b0e3
docs: remove debug info
mkflow27 344930f
refactor: change array access
mkflow27 4cc050f
test: remove unnecessary input
mkflow27 82e21f5
refactor: allow optional user data but use default values if none pro…
mkflow27 03e4537
refactor: remove api dependency & update shared poolState
mkflow27 acae0a2
refactor: harcode data, type refactoring
mkflow27 c71efcc
chore: lint
mkflow27 304c4b8
chore: update casing
mkflow27 325e5a6
test: skip nested tests
mkflow27 ac966a3
chore: syntax
mkflow27 4ab2ca3
refactor: return userData in query outputs
mkflow27 30bad2b
chore: lint
mkflow27 4782051
first pass input validator
mkflow27 4eb61ea
handle different input amounts lengths
mkflow27 e3e1766
chore: rename folder
mkflow27 b2007f6
docs: remove debugging comment
mkflow27 a79a673
feat: handle reference amount not pool token
mkflow27 88b755b
refactor: delete unnecessary additions
mkflow27 87d7742
fix: remove inaccurate assessment due to getAmounts being used
mkflow27 30a62d8
feat: expose optional userData arg for buildCall
mkflow27 8934f9d
feat: userData for remove liq
mkflow27 2518815
Merge branch 'main' into feat-boosted-pool-add-and-remove
mkflow27 ee784f5
chore: remove duplicate
mkflow27 fd9b7c4
chore: lint
mkflow27 2b615f0
refactor: addLiquidity.
johngrantuk d3a4091
refactor: removeLiquidity.
johngrantuk 3a5b3ca
refactor: InputValidator.
johngrantuk f3ede14
fix: access underlyingToken
mkflow27 c4d8410
style: remove logs
mkflow27 98734f7
Merge pull request #456 from balancer/feat-boosted-pool-add-and-remov…
mkflow27 1ce9784
chore: add changeset
mkflow27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
@@ -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 { | ||
totalShares | ||
} | ||
} | ||
}`; | ||
|
||
constructor(private readonly balancerApiClient: BalancerApiClient) {} | ||
|
||
async fetchPoolState(id: string): Promise<PoolState> { | ||
|
@@ -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}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can remove this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed. |
||
totalShares: data.poolGetPool.dynamicData.totalShares, | ||
}; | ||
return poolStateWithUnderlyings; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/entities/addLiquidityBoosted/doAddLiquidityPropotionalQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
src/entities/addLiquidityBoosted/doAddLiquidityUnbalancedQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.