diff --git a/testData/src/abi/vaultExplorer.ts b/testData/src/abi/vaultExplorer.ts new file mode 100644 index 0000000..f3b8cbb --- /dev/null +++ b/testData/src/abi/vaultExplorer.ts @@ -0,0 +1,668 @@ +export const vaultExplorerAbi = [ + { + inputs: [ + { internalType: 'contract IVault', name: 'vault', type: 'address' }, + ], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + inputs: [ + { internalType: 'address', name: 'token', type: 'address' }, + { internalType: 'address', name: 'owner', type: 'address' }, + { internalType: 'address', name: 'spender', type: 'address' }, + ], + name: 'allowance', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { internalType: 'address', name: 'token', type: 'address' }, + { internalType: 'address', name: 'account', type: 'address' }, + ], + name: 'balanceOf', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], + name: 'collectAggregateFees', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { internalType: 'address', name: 'pool', type: 'address' }, + { + components: [ + { + internalType: 'enum SwapKind', + name: 'kind', + type: 'uint8', + }, + { + internalType: 'uint256', + name: 'amountGivenScaled18', + type: 'uint256', + }, + { + internalType: 'uint256[]', + name: 'balancesScaled18', + type: 'uint256[]', + }, + { + internalType: 'uint256', + name: 'indexIn', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'indexOut', + type: 'uint256', + }, + { + internalType: 'address', + name: 'router', + type: 'address', + }, + { internalType: 'bytes', name: 'userData', type: 'bytes' }, + ], + internalType: 'struct IBasePool.PoolSwapParams', + name: 'swapParams', + type: 'tuple', + }, + ], + name: 'computeDynamicSwapFeePercentage', + outputs: [ + { internalType: 'bool', name: 'success', type: 'bool' }, + { + internalType: 'uint256', + name: 'dynamicSwapFee', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { internalType: 'address', name: 'pool', type: 'address' }, + { internalType: 'contract IERC20', name: 'token', type: 'address' }, + ], + name: 'getAggregateSwapFeeAmount', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { internalType: 'address', name: 'pool', type: 'address' }, + { internalType: 'contract IERC20', name: 'token', type: 'address' }, + ], + name: 'getAggregateYieldFeeAmount', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getAuthorizer', + outputs: [{ internalType: 'address', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], + name: 'getBptRate', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { internalType: 'contract IERC20', name: 'token', type: 'address' }, + ], + name: 'getBufferBalance', + outputs: [ + { internalType: 'uint256', name: '', type: 'uint256' }, + { internalType: 'uint256', name: '', type: 'uint256' }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { internalType: 'contract IERC20', name: 'token', type: 'address' }, + { internalType: 'address', name: 'user', type: 'address' }, + ], + name: 'getBufferOwnerShares', + outputs: [{ internalType: 'uint256', name: 'shares', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getBufferPeriodDuration', + outputs: [{ internalType: 'uint32', name: '', type: 'uint32' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getBufferPeriodEndTime', + outputs: [{ internalType: 'uint32', name: '', type: 'uint32' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { internalType: 'contract IERC20', name: 'token', type: 'address' }, + ], + name: 'getBufferTotalShares', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], + name: 'getCurrentLiveBalances', + outputs: [{ internalType: 'uint256[]', name: '', type: 'uint256[]' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], + name: 'getHooksConfig', + outputs: [ + { + components: [ + { + internalType: 'bool', + name: 'enableHookAdjustedAmounts', + type: 'bool', + }, + { + internalType: 'bool', + name: 'shouldCallBeforeInitialize', + type: 'bool', + }, + { + internalType: 'bool', + name: 'shouldCallAfterInitialize', + type: 'bool', + }, + { + internalType: 'bool', + name: 'shouldCallComputeDynamicSwapFee', + type: 'bool', + }, + { + internalType: 'bool', + name: 'shouldCallBeforeSwap', + type: 'bool', + }, + { + internalType: 'bool', + name: 'shouldCallAfterSwap', + type: 'bool', + }, + { + internalType: 'bool', + name: 'shouldCallBeforeAddLiquidity', + type: 'bool', + }, + { + internalType: 'bool', + name: 'shouldCallAfterAddLiquidity', + type: 'bool', + }, + { + internalType: 'bool', + name: 'shouldCallBeforeRemoveLiquidity', + type: 'bool', + }, + { + internalType: 'bool', + name: 'shouldCallAfterRemoveLiquidity', + type: 'bool', + }, + { + internalType: 'address', + name: 'hooksContract', + type: 'address', + }, + ], + internalType: 'struct HooksConfig', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getMaximumPoolTokens', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getMinimumPoolTokens', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getNonzeroDeltaCount', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getPauseWindowEndTime', + outputs: [{ internalType: 'uint32', name: '', type: 'uint32' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], + name: 'getPoolConfig', + outputs: [ + { + components: [ + { + components: [ + { + internalType: 'bool', + name: 'disableUnbalancedLiquidity', + type: 'bool', + }, + { + internalType: 'bool', + name: 'enableAddLiquidityCustom', + type: 'bool', + }, + { + internalType: 'bool', + name: 'enableRemoveLiquidityCustom', + type: 'bool', + }, + { + internalType: 'bool', + name: 'enableDonation', + type: 'bool', + }, + ], + internalType: 'struct LiquidityManagement', + name: 'liquidityManagement', + type: 'tuple', + }, + { + internalType: 'uint256', + name: 'staticSwapFeePercentage', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'aggregateSwapFeePercentage', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'aggregateYieldFeePercentage', + type: 'uint256', + }, + { + internalType: 'uint24', + name: 'tokenDecimalDiffs', + type: 'uint24', + }, + { + internalType: 'uint32', + name: 'pauseWindowEndTime', + type: 'uint32', + }, + { + internalType: 'bool', + name: 'isPoolRegistered', + type: 'bool', + }, + { + internalType: 'bool', + name: 'isPoolInitialized', + type: 'bool', + }, + { + internalType: 'bool', + name: 'isPoolPaused', + type: 'bool', + }, + { + internalType: 'bool', + name: 'isPoolInRecoveryMode', + type: 'bool', + }, + ], + internalType: 'struct PoolConfig', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], + name: 'getPoolData', + outputs: [ + { + components: [ + { + internalType: 'PoolConfigBits', + name: 'poolConfigBits', + type: 'bytes32', + }, + { + internalType: 'contract IERC20[]', + name: 'tokens', + type: 'address[]', + }, + { + components: [ + { + internalType: 'enum TokenType', + name: 'tokenType', + type: 'uint8', + }, + { + internalType: 'contract IRateProvider', + name: 'rateProvider', + type: 'address', + }, + { + internalType: 'bool', + name: 'paysYieldFees', + type: 'bool', + }, + ], + internalType: 'struct TokenInfo[]', + name: 'tokenInfo', + type: 'tuple[]', + }, + { + internalType: 'uint256[]', + name: 'balancesRaw', + type: 'uint256[]', + }, + { + internalType: 'uint256[]', + name: 'balancesLiveScaled18', + type: 'uint256[]', + }, + { + internalType: 'uint256[]', + name: 'tokenRates', + type: 'uint256[]', + }, + { + internalType: 'uint256[]', + name: 'decimalScalingFactors', + type: 'uint256[]', + }, + ], + internalType: 'struct PoolData', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], + name: 'getPoolPausedState', + outputs: [ + { internalType: 'bool', name: '', type: 'bool' }, + { internalType: 'uint32', name: '', type: 'uint32' }, + { internalType: 'uint32', name: '', type: 'uint32' }, + { internalType: 'address', name: '', type: 'address' }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], + name: 'getPoolRoleAccounts', + outputs: [ + { + components: [ + { + internalType: 'address', + name: 'pauseManager', + type: 'address', + }, + { + internalType: 'address', + name: 'swapFeeManager', + type: 'address', + }, + { + internalType: 'address', + name: 'poolCreator', + type: 'address', + }, + ], + internalType: 'struct PoolRoleAccounts', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { internalType: 'address', name: 'pool', type: 'address' }, + { internalType: 'contract IERC20', name: 'token', type: 'address' }, + ], + name: 'getPoolTokenCountAndIndexOfToken', + outputs: [ + { internalType: 'uint256', name: '', type: 'uint256' }, + { internalType: 'uint256', name: '', type: 'uint256' }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], + name: 'getPoolTokenInfo', + outputs: [ + { + internalType: 'contract IERC20[]', + name: 'tokens', + type: 'address[]', + }, + { + components: [ + { + internalType: 'enum TokenType', + name: 'tokenType', + type: 'uint8', + }, + { + internalType: 'contract IRateProvider', + name: 'rateProvider', + type: 'address', + }, + { + internalType: 'bool', + name: 'paysYieldFees', + type: 'bool', + }, + ], + internalType: 'struct TokenInfo[]', + name: 'tokenInfo', + type: 'tuple[]', + }, + { + internalType: 'uint256[]', + name: 'balancesRaw', + type: 'uint256[]', + }, + { + internalType: 'uint256[]', + name: 'scalingFactors', + type: 'uint256[]', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], + name: 'getPoolTokenRates', + outputs: [ + { internalType: 'uint256[]', name: '', type: 'uint256[]' }, + { internalType: 'uint256[]', name: '', type: 'uint256[]' }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], + name: 'getPoolTokens', + outputs: [ + { internalType: 'contract IERC20[]', name: '', type: 'address[]' }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getProtocolFeeController', + outputs: [{ internalType: 'address', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { internalType: 'contract IERC20', name: 'token', type: 'address' }, + ], + name: 'getReservesOf', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], + name: 'getStaticSwapFeePercentage', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { internalType: 'contract IERC20', name: 'token', type: 'address' }, + ], + name: 'getTokenDelta', + outputs: [{ internalType: 'int256', name: '', type: 'int256' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getVault', + outputs: [{ internalType: 'address', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getVaultAdmin', + outputs: [{ internalType: 'address', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getVaultExtension', + outputs: [{ internalType: 'address', name: '', type: 'address' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getVaultPausedState', + outputs: [ + { internalType: 'bool', name: '', type: 'bool' }, + { internalType: 'uint32', name: '', type: 'uint32' }, + { internalType: 'uint32', name: '', type: 'uint32' }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], + name: 'isPoolInRecoveryMode', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], + name: 'isPoolInitialized', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], + name: 'isPoolPaused', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'pool', type: 'address' }], + name: 'isPoolRegistered', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'isQueryDisabled', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'isUnlocked', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'isVaultPaused', + outputs: [{ internalType: 'bool', name: '', type: 'bool' }], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [{ internalType: 'address', name: 'token', type: 'address' }], + name: 'totalSupply', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + stateMutability: 'view', + type: 'function', + }, +] as const; diff --git a/testData/src/stablePool.ts b/testData/src/stablePool.ts index f5920d4..439d509 100644 --- a/testData/src/stablePool.ts +++ b/testData/src/stablePool.ts @@ -7,6 +7,7 @@ import { type Chain, } from 'viem'; import { CHAINS, VAULT_V3, vaultExtensionV3Abi } from '@balancer/sdk'; +import { vaultExplorerAbi } from './abi/vaultExplorer'; type StableMutable = { amp: bigint; @@ -14,6 +15,7 @@ type StableMutable = { totalSupply: bigint; balancesLiveScaled18: bigint[]; tokenRates: bigint[]; + aggregateSwapFee: bigint; }; type StableImmutable = { @@ -72,12 +74,6 @@ export class StablePool { async fetchMutableData( address: Address, ): Promise> { - const staticSwapFeeCall = { - address: this.vault, - abi: vaultExtensionV3Abi, - functionName: 'getStaticSwapFeePercentage', - args: [address], - } as const; const totalSupplyCall = { address: this.vault, abi: parseAbi([ @@ -105,23 +101,31 @@ export class StablePool { ]), functionName: 'getAmplificationParameter', } as const; + const poolConfigCall = { + address: this.vault, + abi: vaultExplorerAbi, + functionName: 'getPoolConfig', + args: [address], + } as const; const multicallResult = await this.client.multicall({ contracts: [ - staticSwapFeeCall, totalSupplyCall, liveBalancesCall, tokenRatesCall, amplificationParameterCall, + poolConfigCall, ], allowFailure: false, }); return { - swapFee: multicallResult[0].toString(), - totalSupply: multicallResult[1].toString(), - balancesLiveScaled18: multicallResult[2].map((b) => b.toString()), - tokenRates: multicallResult[3][1].map((b) => b.toString()), - amp: multicallResult[4][0].toString(), + swapFee: multicallResult[4].staticSwapFeePercentage.toString(), + totalSupply: multicallResult[0].toString(), + balancesLiveScaled18: multicallResult[1].map((b) => b.toString()), + tokenRates: multicallResult[2][1].map((b) => b.toString()), + amp: multicallResult[3][0].toString(), + aggregateSwapFee: + multicallResult[4].aggregateSwapFeePercentage.toString(), }; } } diff --git a/testData/src/weightedPool.ts b/testData/src/weightedPool.ts index 297f17d..5cf6a64 100644 --- a/testData/src/weightedPool.ts +++ b/testData/src/weightedPool.ts @@ -7,6 +7,7 @@ import { type Chain, } from 'viem'; import { CHAINS, VAULT_V3, vaultExtensionV3Abi } from '@balancer/sdk'; +import { vaultExplorerAbi } from './abi/vaultExplorer'; export type WeightedImmutable = { tokens: bigint[]; @@ -19,6 +20,7 @@ type WeightedMutable = { totalSupply: bigint; balancesLiveScaled18: bigint[]; tokenRates: bigint[]; + aggregateSwapFee: bigint; }; type TransformBigintToString = { @@ -81,12 +83,6 @@ export class WeightedPool { async fetchMutableData( address: Address, ): Promise> { - const staticSwapFeeCall = { - address: this.vault, - abi: vaultExtensionV3Abi, - functionName: 'getStaticSwapFeePercentage', - args: [address], - } as const; const totalSupplyCall = { address: this.vault, abi: parseAbi([ @@ -107,21 +103,29 @@ export class WeightedPool { functionName: 'getPoolTokenRates', args: [address], } as const; + const poolConfigCall = { + address: this.vault, + abi: vaultExplorerAbi, + functionName: 'getPoolConfig', + args: [address], + } as const; const multicallResult = await this.client.multicall({ contracts: [ - staticSwapFeeCall, totalSupplyCall, liveBalancesCall, tokenRatesCall, + poolConfigCall, ], allowFailure: false, }); return { - swapFee: multicallResult[0].toString(), - totalSupply: multicallResult[1].toString(), - balancesLiveScaled18: multicallResult[2].map((b) => b.toString()), - tokenRates: multicallResult[3][1].map((b) => b.toString()), + swapFee: multicallResult[3].staticSwapFeePercentage.toString(), + totalSupply: multicallResult[0].toString(), + balancesLiveScaled18: multicallResult[1].map((b) => b.toString()), + tokenRates: multicallResult[2][1].map((b) => b.toString()), + aggregateSwapFee: + multicallResult[3].aggregateSwapFeePercentage.toString(), }; } } diff --git a/testData/testData/11155111-5955145-Weighted.json b/testData/testData/11155111-5955145-Weighted.json index f5fbaa3..4921bd5 100644 --- a/testData/testData/11155111-5955145-Weighted.json +++ b/testData/testData/11155111-5955145-Weighted.json @@ -85,6 +85,7 @@ "tokenRates": [ "1000000000000000000", "1000000000000000000" - ] + ], + "aggregateSwapFee": "0" } } \ No newline at end of file diff --git a/testData/testData/11155111-5955146-Weighted.json b/testData/testData/11155111-5955146-Weighted.json index ef5dec3..758fad9 100644 --- a/testData/testData/11155111-5955146-Weighted.json +++ b/testData/testData/11155111-5955146-Weighted.json @@ -41,6 +41,7 @@ "tokenRates": [ "1000000000000000000", "1000000000000000000" - ] + ], + "aggregateSwapFee": "0" } } \ No newline at end of file diff --git a/testData/testData/11155111-6113328-Stable.json b/testData/testData/11155111-6113328-Stable.json index ea5e23d..81aa9fa 100644 --- a/testData/testData/11155111-6113328-Stable.json +++ b/testData/testData/11155111-6113328-Stable.json @@ -5,14 +5,14 @@ "amountRaw": "1000000000000000", "tokenIn": "0x8a88124522dbbf1e56352ba3de1d9f78c143751e", "tokenOut": "0xde46e43f46ff74a23a65ebb0580cbe3dfe684a17", - "outputRaw": "494999999999999872727" + "outputRaw": "494999999999999872808" }, { "swapKind": 1, "amountRaw": "2000000000000000", "tokenIn": "0x8a88124522dbbf1e56352ba3de1d9f78c143751e", "tokenOut": "0xde46e43f46ff74a23a65ebb0580cbe3dfe684a17", - "outputRaw": "2132" + "outputRaw": "2130" } ], "adds": [ @@ -22,7 +22,7 @@ "1000000000000000", "1000000000000000" ], - "bptOutRaw": "155907863911003536972201225" + "bptOutRaw": "155944446591312671139105900" }, { "kind": "SingleToken", @@ -45,7 +45,7 @@ { "kind": "SingleTokenExactIn", "amountsOutRaw": [ - "969600", + "969017", "0" ], "bptInRaw": "1000000000000000000" @@ -56,7 +56,7 @@ "1000000", "0" ], - "bptInRaw": "1031378931593220589" + "bptInRaw": "1031999447043161374" } ], "pool": { @@ -75,13 +75,14 @@ "swapFee": "10000000000000000", "totalSupply": "1054451151293881721519", "balancesLiveScaled18": [ - "518892950064978587500", - "547641471206153917000" + "520743963834780023000", + "548947641668610913500" ], "tokenRates": [ - "1037785900129957175", - "1095282942412307834" + "1041487927669560046", + "1097895283337221827" ], - "amp": "1000000" + "amp": "1000000", + "aggregateSwapFee": "0" } } \ No newline at end of file