Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/nasty-vans-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@balancer/sdk": minor
---

Add StableSurge create support.
298 changes: 298 additions & 0 deletions src/abi/stableSurgeFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
export const stableSurgeFactoryAbi = [
{
inputs: [
{ internalType: 'contract IVault', name: 'vault', type: 'address' },
{
internalType: 'uint32',
name: 'pauseWindowDuration',
type: 'uint32',
},
{
internalType: 'uint256',
name: 'defaultMaxSurgeFeePercentage',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'defaultSurgeThresholdPercentage',
type: 'uint256',
},
{ internalType: 'string', name: 'factoryVersion', type: 'string' },
{ internalType: 'string', name: 'poolVersion', type: 'string' },
],
stateMutability: 'nonpayable',
type: 'constructor',
},
{ inputs: [], name: 'Create2EmptyBytecode', type: 'error' },
{ inputs: [], name: 'Create2FailedDeployment', type: 'error' },
{
inputs: [
{ internalType: 'uint256', name: 'balance', type: 'uint256' },
{ internalType: 'uint256', name: 'needed', type: 'uint256' },
],
name: 'Create2InsufficientBalance',
type: 'error',
},
{ inputs: [], name: 'Disabled', type: 'error' },
{ inputs: [], name: 'IndexOutOfBounds', type: 'error' },
{ inputs: [], name: 'MaxTokens', type: 'error' },
{ inputs: [], name: 'PoolPauseWindowDurationOverflow', type: 'error' },
{ inputs: [], name: 'SenderNotAllowed', type: 'error' },
{ inputs: [], name: 'StandardPoolWithCreator', type: 'error' },
{ anonymous: false, inputs: [], name: 'FactoryDisabled', type: 'event' },
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'pool',
type: 'address',
},
],
name: 'PoolCreated',
type: 'event',
},
{
inputs: [
{ internalType: 'string', name: 'name', type: 'string' },
{ internalType: 'string', name: 'symbol', type: 'string' },
{
components: [
{
internalType: 'contract IERC20',
name: 'token',
type: 'address',
},
{
internalType: 'enum TokenType',
name: 'tokenType',
type: 'uint8',
},
{
internalType: 'contract IRateProvider',
name: 'rateProvider',
type: 'address',
},
{
internalType: 'bool',
name: 'paysYieldFees',
type: 'bool',
},
],
internalType: 'struct TokenConfig[]',
name: 'tokens',
type: 'tuple[]',
},
{
internalType: 'uint256',
name: 'amplificationParameter',
type: 'uint256',
},
{
components: [
{
internalType: 'address',
name: 'pauseManager',
type: 'address',
},
{
internalType: 'address',
name: 'swapFeeManager',
type: 'address',
},
{
internalType: 'address',
name: 'poolCreator',
type: 'address',
},
],
internalType: 'struct PoolRoleAccounts',
name: 'roleAccounts',
type: 'tuple',
},
{
internalType: 'uint256',
name: 'swapFeePercentage',
type: 'uint256',
},
{ internalType: 'bool', name: 'enableDonation', type: 'bool' },
{
internalType: 'bool',
name: 'disableUnbalancedLiquidity',
type: 'bool',
},
{ internalType: 'bytes32', name: 'salt', type: 'bytes32' },
],
name: 'create',
outputs: [{ internalType: 'address', name: 'pool', type: 'address' }],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [],
name: 'disable',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [{ internalType: 'bytes4', name: 'selector', type: 'bytes4' }],
name: 'getActionId',
outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'getAuthorizer',
outputs: [
{ internalType: 'contract IAuthorizer', name: '', type: 'address' },
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'getDefaultLiquidityManagement',
outputs: [
{
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',
},
],
stateMutability: 'pure',
type: 'function',
},
{
inputs: [],
name: 'getDefaultPoolHooksContract',
outputs: [{ internalType: 'address', name: '', type: 'address' }],
stateMutability: 'pure',
type: 'function',
},
{
inputs: [
{ internalType: 'bytes', name: 'constructorArgs', type: 'bytes' },
{ internalType: 'bytes32', name: 'salt', type: 'bytes32' },
],
name: 'getDeploymentAddress',
outputs: [{ internalType: 'address', name: '', type: 'address' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'getNewPoolPauseWindowEndTime',
outputs: [{ internalType: 'uint32', name: '', type: 'uint32' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'getOriginalPauseWindowEndTime',
outputs: [{ internalType: 'uint32', name: '', type: 'uint32' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'getPauseWindowDuration',
outputs: [{ internalType: 'uint32', name: '', type: 'uint32' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'getPoolCount',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'getPoolVersion',
outputs: [{ internalType: 'string', name: '', type: 'string' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'getPools',
outputs: [{ internalType: 'address[]', name: '', type: 'address[]' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{ internalType: 'uint256', name: 'start', type: 'uint256' },
{ internalType: 'uint256', name: 'count', type: 'uint256' },
],
name: 'getPoolsInRange',
outputs: [
{ internalType: 'address[]', name: 'pools', type: 'address[]' },
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'getStableSurgeHook',
outputs: [{ internalType: 'address', name: '', type: 'address' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'getVault',
outputs: [
{ internalType: 'contract IVault', name: '', type: 'address' },
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'isDisabled',
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [{ internalType: 'address', name: 'pool', type: 'address' }],
name: 'isPoolFromFactory',
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'version',
outputs: [{ internalType: 'string', name: '', type: 'string' }],
stateMutability: 'view',
type: 'function',
},
] as const;
2 changes: 2 additions & 0 deletions src/entities/createPool/createPoolV3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '../types';
import { CreatePoolWeightedV3 } from './weighted/createPoolWeighted';
import { CreatePoolStableV3 } from './stable/createPoolStable';
import { CreatePoolStableSurge } from './stableSurge/createStableSurge';

export class CreatePoolV3 implements CreatePoolBase {
private readonly createPoolTypes: Record<string, CreatePoolBase> = {};
Expand All @@ -14,6 +15,7 @@ export class CreatePoolV3 implements CreatePoolBase {
this.createPoolTypes = {
[PoolType.Weighted]: new CreatePoolWeightedV3(),
[PoolType.Stable]: new CreatePoolStableV3(),
[PoolType.StableSurge]: new CreatePoolStableSurge(),
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { getRandomBytes32 } from '@/entities/utils/getRandomBytes32';
import { encodeFunctionData, zeroAddress } from 'viem';
import {
CreatePoolBase,
CreatePoolBuildCallOutput,
PoolRoleAccounts,
CreatePoolStableSurgeInput,
} from '../../types';
import { stableSurgeFactoryAbi } from '@/abi/stableSurgeFactory';
import { STABLE_SURGE_FACTORY, sortByAddress } from '@/utils';
import { Hex } from '@/types';

export class CreatePoolStableSurge implements CreatePoolBase {
buildCall(input: CreatePoolStableSurgeInput): CreatePoolBuildCallOutput {
const callData = this.encodeCall(input);
return {
callData,
to: STABLE_SURGE_FACTORY[input.chainId],
};
}

private encodeCall(input: CreatePoolStableSurgeInput): Hex {
const sortedTokenConfigs = sortByAddress(input.tokens);

const roleAccounts: PoolRoleAccounts = {
pauseManager: input.pauseManager,
swapFeeManager: input.swapFeeManager,
poolCreator: zeroAddress, // balancer core pool types are not allowed to have a creator
};

const args = [
input.name || input.symbol,
input.symbol,
sortedTokenConfigs.map(
({ address, rateProvider, tokenType, paysYieldFees }) => ({
token: address,
tokenType,
rateProvider,
paysYieldFees,
}),
),
input.amplificationParameter,
roleAccounts,
input.swapFeePercentage,
input.enableDonation,
input.disableUnbalancedLiquidity,
input.salt || getRandomBytes32(),
] as const;

return encodeFunctionData({
abi: stableSurgeFactoryAbi,
functionName: 'create',
args,
});
}
}
1 change: 1 addition & 0 deletions src/entities/createPool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CreatePoolV2 } from './createPoolV2';
import { CreatePoolV3 } from './createPoolV3';

export * from './types';
export * from './createPoolV3/stableSurge/createStableSurge';

export class CreatePool implements CreatePoolBase {
private readonly inputValidator: InputValidator;
Expand Down
Loading