Skip to content

Commit

Permalink
fix a few issues with redeems
Browse files Browse the repository at this point in the history
  • Loading branch information
jankjr committed Jan 15, 2025
1 parent 0398036 commit 835e1fe
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 126 deletions.
7 changes: 5 additions & 2 deletions src.ts/action/Balancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const loadPoolsFromAPI = async (chainId: ChainId) => {
const chainIn = chainIdToChainIn[chainId]
const where = {
chainIn: [chainIn],
minTvl: 0,
minTvl: 200000,
poolTypeIn: POOLTYPES,
tagIn: null,
tagNotIn: ['BLACK_LISTED'],
Expand Down Expand Up @@ -174,10 +174,12 @@ const loadPoolsFromAPI = async (chainId: ChainId) => {
const json = await response.json()
if (!json.data) {
console.error(JSON.stringify(json, null, 2))
console.log('Failed to load pools from Balancer API')
throw new Error(
`No data returned from Balancer API: ${JSON.stringify(json)}`
)
}

return json.data.poolGetPools as IBalancerPool[]
}

Expand Down Expand Up @@ -316,7 +318,7 @@ export class BalancerSwap extends BaseAction {
// uint256 deadline;
// IBalancerVault.SwapKind kind;
// }
let minOut = predictedOutput[0].amount - predictedOutput[0].amount / 20n
let minOut = 0n //predictedOutput[0].amount - predictedOutput[0].amount / 5n

const encodedStaticData = ethers.utils.defaultAbiCoder.encode(
[
Expand Down Expand Up @@ -466,6 +468,7 @@ export const setupBalancer = async (universe: Universe) => {

for (const pool of pools) {
for (const action of pool.actions) {
// console.log(action.toString())
universe.addAction(action)
}
}
Expand Down
3 changes: 2 additions & 1 deletion src.ts/action/Curve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ const dontLoadPools = new Set(
'0x8e27f0821873b6f5421b6ca75a4c5e1e83d3e77a',
'0x6a0861625937cb3629066cc6db88808a590b9c68',
'0x498ad3352ccfaed237a91f6933a92a7a43917b72',
'0xd82C2eB10F4895CABED6EDa6eeee234bd1A9838B',
'0xd6b03059c882f63268dd3e1a98d8e3cdee26919c',
'0xa15e8f7e1e031e4f6f11053c6d320b2a8dc6742c',
'0x6a52e339a4b8abd15707f882d6adc05875ec5223',
Expand Down Expand Up @@ -478,7 +479,7 @@ export class CurveSwap extends Action('Curve') {

const { route, swapParams } = this.routeParams(true)

const minOut = output.amount - output.amount / 20n
const minOut = 0n // output.amount - output.amount / 5n
// function exchangeNew(
// uint256 amountIn,
// bytes memory encodedRouterCall
Expand Down
28 changes: 16 additions & 12 deletions src.ts/action/CurveFactoryCryptoPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,37 +128,40 @@ class CryptoFactoryPoolRemoveLiquidity extends CurveFactoryCryptoPoolBase {
balance0: bal0,
balance1: bal1,
} = await this.pool.poolInfo()
const [token0, token1] = this.pool.allPoolTokens
return [
bal0
.fpMul(amount.amount, amount.token.scale)
.div(totalSupply.into(token0)),
bal1
.fpMul(amount.amount, amount.token.scale)
.div(totalSupply.into(token1)),
bal0.token.from((bal0.amount * amount.amount) / totalSupply.amount),
bal1.token.from((bal1.amount * amount.amount) / totalSupply.amount),
]
}

async plan(
planner: Planner,
[input]: Value[],
_: Address,
dest: Address,
[lpAmt]: TokenQuantity[]
) {
const [amt0, amt1] = await this.quote([lpAmt])
console.log(lpAmt.toString(), amt0.toString(), amt1.toString())
const lib = this.gen.Contract.createContract(this.pool.poolInstance)
planner.add(
lib.remove_liquidity(
input,
encodeArg(
[amt0.amount - amt0.amount / 100n, amt1.amount - amt1.amount / 100n],
[amt0.amount - amt0.amount / 50n, amt1.amount - amt1.amount / 50n],
ParamType.fromString('uint256[2]')
),
false
)
false,
dest.address
),
`${this.protocol}.${
this.actionName
}(${lpAmt.toString()}) -> ${amt0.toString()}, ${amt1.toString()}`
)
return null
}
get actionName() {
return 'remove_liquidity'
}

constructor(public readonly pool: CurveFactoryCryptoPool) {
super(
Expand Down Expand Up @@ -224,7 +227,8 @@ export class CurveFactoryCryptoPool {
remove_liquidity: (
amount: BigNumberish,
amounts: [BigNumberish, BigNumberish],
use_eth: boolean
use_eth: boolean,
recipient: string
) => Promise<[BigNumber, BigNumber]>
add_liquidity: (
amounts: [BigNumberish, BigNumberish],
Expand Down
2 changes: 1 addition & 1 deletion src.ts/configuration/setupUniswapRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class UniswapV3Swap extends Action('UniswapV3') {
)
// console.log(`${this}: ${predictedInput} -> ${amountOut}`)

const minOut = amountOut.amount - amountOut.amount / 20n
const minOut = 0n // amountOut.amount - amountOut.amount / 20n
const out = planner.add(
this.context.weirollRouterCall.exactInputSingle(
input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@
{
"name": "use_eth",
"type": "bool"
},
{
"name": "recipient",
"type": "address"
}
],
"outputs": []
Expand Down
Loading

0 comments on commit 835e1fe

Please sign in to comment.