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

SwapV3 does not handle BPT -> Token swaps #413

Open
mkflow27 opened this issue Sep 13, 2024 · 0 comments
Open

SwapV3 does not handle BPT -> Token swaps #413

mkflow27 opened this issue Sep 13, 2024 · 0 comments

Comments

@mkflow27
Copy link
Contributor

mkflow27 commented Sep 13, 2024

My understanding is that the intention for SwapV3 is to also handle BPT -> Token swaps. Currently this path is not implemented. The issue arose when working on balancer/backend#896. The pool used was part of the seventh vault deployment. The pool in question (deployed with the ExitFeeHook) is https://sepolia.etherscan.io/address/0xc7436329da34B54fAD1400f400931751E1D06Cf8. package version used was
"@balancer/sdk": "0.25.0"

The relevant code:

const queryOutput = await sdkSwap.query(rpcUrl);
In this case is wanting do query a singleSwapExactIn where the BPT (TokenIn) and WETH (tokenOut). This leads to a TokenNotRegistered["0xc7436329da34b54fad1400f400931751e1d06cf8"]
in the Vault - see this sim: https://dashboard.tenderly.co/mcquardt/project/simulator/14613a09-4243-46a2-9807-a0d5b47c5776

The pool used is:

prismaWeightedPool = prismaPoolFactory.build({
    address: '0xc7436329da34B54fAD1400f400931751E1D06Cf8',
    type: 'WEIGHTED',
    protocolVersion,
    tokens: [WETH, BAL],
    dynamicData: prismaPoolDynamicDataFactory.build({
        totalShares: '0.158113883008415798',
        swapFee: '0.1',
    }),
});



// The token in needs to be the BPT
const tIn = new Token(
    parseFloat('11155111'),
    prismaWeightedPool.address as Address,
    prismaWeightedPool.decimals,
);
const tOut = new Token(
    parseFloat(chainToIdMap[WETH.token.chain]),
    WETH.address as Address,
    WETH.token.decimals,
);
const amountIn = BigInt(1000e6);
paths = (await sorGetPathsWithPools(
    tIn,
    tOut,
    SwapKind.GivenIn,
    amountIn,
    [prismaStablePool, prismaWeightedPool],
    protocolVersion,
    [prismaHook1, prismaHook2],
)) as PathWithAmount[];

const swapPaths: Path[] = paths.map((path) => ({
    protocolVersion,
    inputAmountRaw: path.inputAmount.amount,
    outputAmountRaw: path.outputAmount.amount,
    tokens: path.tokens.map((token) => ({
        address: token.address,
        decimals: token.decimals,
    })),
    pools: path.pools.map((pool) => pool.id),
}));

// build SDK swap from SOR paths
sdkSwap = new Swap({
    chainId: parseFloat(chainToIdMap['SEPOLIA']),
    paths: swapPaths,
    swapKind: SwapKind.GivenIn,
});

const returnAmountSOR = getOutputAmount(paths);
const queryOutput = await sdkSwap.query(rpcUrl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant