Skip to content

Commit

Permalink
feat: update component slippage (#100)
Browse files Browse the repository at this point in the history
* revert changes

* feat: update to lower slippage
  • Loading branch information
janndriessen authored Dec 12, 2024
1 parent 4881d65 commit faf14b0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci
# - run: npm run lint
- run: npm run lint
- run: npm run build --if-present
- run: npm run hardhat:arbitrum &
- run: npm run hardhat:base &
Expand Down
13 changes: 6 additions & 7 deletions src/utils/component-swap-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,12 @@ export async function getIssuanceComponentSwapData(
getUnderlyingErc20(component, chainId)
)
const units = issuanceUnits.map((unit: BigNumber) => unit.toString())
console.log({issuanceComponents, units, indexTokenAmount: indexTokenAmount.toString()})
const amountPromises = issuanceComponents.map(
(component: Address, index: number) =>
getAmount(true, component, BigInt(units[index]), chainId)
)
const wrappedTokens = await Promise.all(underlyingERC20sPromises)
const amounts: bigint[] = await Promise.all(amountPromises)
console.log({indexTokenAmount: indexTokenAmount.toString(), amounts});
const swapPromises: Promise<SwapQuote | null>[] = issuanceComponents.map(
(_: string, index: number) => {
const wrappedToken = wrappedTokens[index]
Expand Down Expand Up @@ -203,22 +201,23 @@ async function getAmount(
'function previewMint(uint256 shares) view returns (uint256 assets)',
'function previewRedeem(uint256 shares) view returns (uint256 assets)',
]
// console.log('gettingPreview for', {component})
const preview: bigint = (await publicClient.readContract({
address: component as Address,
abi: parseAbi(erc4626Abi),
functionName: isMinting ? 'previewMint' : 'previewRedeem',
args: [issuanceUnits],
})) as bigint
const previewWithSlippage = isMinting ? preview * BigInt(1001) / BigInt(1000) : preview * BigInt(999) / BigInt(1000)
console.log({component, issuanceUnits, preview, previewWithSlippage})
const previewWithSlippage = isMinting
? (preview * BigInt(10001)) / BigInt(10000)
: (preview * BigInt(9999)) / BigInt(10000)
return previewWithSlippage
} catch {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const usdc = getTokenByChainAndSymbol(chainId, 'USDC')!
if (isAddressEqual(component, usdc)) return issuanceUnits
const issuanceUnitsWithSlippage = isMinting ? (issuanceUnits * BigInt(1005)) / BigInt(1000) : (issuanceUnits * BigInt(995)) / BigInt(1000)
console.log({component, issuanceUnits, issuanceUnitsWithSlippage})
const issuanceUnitsWithSlippage = isMinting
? (issuanceUnits * BigInt(1005)) / BigInt(1000)
: (issuanceUnits * BigInt(995)) / BigInt(1000)
return issuanceUnitsWithSlippage
}
}
Expand Down

0 comments on commit faf14b0

Please sign in to comment.