Skip to content

Commit

Permalink
👷‍♂️✨ sdeUSD lev data switch to odos & slippage update (#525)
Browse files Browse the repository at this point in the history
* sdeUSD lev data switch to odos & slippage update

* update sdeUSD delev swapper
  • Loading branch information
0xhardrefresh authored Dec 19, 2024
1 parent 4396af1 commit c8b9d10
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 39 deletions.
99 changes: 99 additions & 0 deletions src/abis/SDEUSDSwapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
export default [
{ inputs: [], stateMutability: "nonpayable", type: "constructor" },
{ inputs: [], name: "ErrSwapFailed", type: "error" },
{
inputs: [],
name: "BALANCER_QUERY",
outputs: [
{ internalType: "contract IBalancerQuery", name: "", type: "address" },
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "BALANCER_SWAPS",
outputs: [
{ internalType: "contract IBalancerSwaps", name: "", type: "address" },
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "BALANCER_VAULT",
outputs: [{ internalType: "address", name: "", type: "address" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "BOX",
outputs: [
{ internalType: "contract IBentoBoxLite", name: "", type: "address" },
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "DEUSD",
outputs: [{ internalType: "address", name: "", type: "address" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "MIM",
outputs: [{ internalType: "address", name: "", type: "address" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "POOL_ID",
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "SDEUSD",
outputs: [{ internalType: "address", name: "", type: "address" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "SWAP_KIND",
outputs: [{ internalType: "enum SwapKind", name: "", type: "uint8" }],
stateMutability: "view",
type: "function",
},
{
inputs: [
{ internalType: "uint256", name: "amountSDEUSD", type: "uint256" },
],
name: "previewSDEUSDOut",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{ internalType: "address", name: "", type: "address" },
{ internalType: "address", name: "", type: "address" },
{ internalType: "address", name: "recipient", type: "address" },
{ internalType: "uint256", name: "shareToMin", type: "uint256" },
{ internalType: "uint256", name: "shareFrom", type: "uint256" },
{ internalType: "bytes", name: "data", type: "bytes" },
],
name: "swap",
outputs: [
{ internalType: "uint256", name: "extraShare", type: "uint256" },
{ internalType: "uint256", name: "shareReturned", type: "uint256" },
],
stateMutability: "nonpayable",
type: "function",
},
];
4 changes: 2 additions & 2 deletions src/components/popups/SlippagePopup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
v-model="inputValue"
min="0"
max="100"
step="1"
type="text"
step="0.1"
type="number"
placeholder="1 - 100"
/>

Expand Down
5 changes: 3 additions & 2 deletions src/configs/cauldrons/ethereumCauldrons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ConvexWrapperLevSwapper from "@/abis/ConvexWrapperLevSwapper";
import YearnLevSwapper from "@/abis/YearnLevSwapper";
import ConvexWrapperSwapper from "@/abis/ConvexWrapperSwapper";
import YearnSwapper from "@/abis/YearnSwapper";
import SDEUSDSwapper from "@/abis/SDEUSDSwapper";
import { useImage } from "@/helpers/useImage";
import { GNOSIS_SAFE_ADDRESS } from "@/constants/global";

Expand Down Expand Up @@ -1770,8 +1771,8 @@ const config: Array<CauldronConfig> = [
abi: ERC4626LevSwapper,
},
deleverageInfo: {
address: "0xd3941893cFd1a563333f7383259b21dAf34C14A8",
abi: ERC4626LiqSwapper,
address: "0x64d4160d5f5efffaf90317c47b80d73b36108180",
abi: SDEUSDSwapper,
},
},
{
Expand Down
6 changes: 4 additions & 2 deletions src/helpers/0x.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumber } from "ethers";
import { BigNumber, utils } from "ethers";
import axios from "axios";
import rateLimit from "axios-rate-limit";

Expand All @@ -10,6 +10,7 @@ const http = rateLimit(axios.create(), {
});

const SLIPPAGE_ACCURACY = 1e4;
const SLIPPAGE_DECIMALS = 4;

const endpoints = {
1: "https://api.0x.org",
Expand Down Expand Up @@ -109,7 +110,8 @@ export const swap0xRequestV2 = async (
amountBuy = 0
) => {
try {
const slippagePercentage = slippage / 100;
const slippageBN = utils.parseUnits(slippage, SLIPPAGE_DECIMALS);
const slippagePercentage = utils.formatUnits(slippageBN.div(100), SLIPPAGE_DECIMALS);

let params;

Expand Down
34 changes: 21 additions & 13 deletions src/helpers/cauldron/cook/0xSwapData/deleverage/fetchDeUSD0xData.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { utils } from "ethers";
import { swap0xRequestV2 } from "@/helpers/0x";
// import { swap0xRequestV2 } from "@/helpers/0x";
import { swapOdosRequest } from "@/helpers/odos";

import type { CauldronInfo } from "@/helpers/cauldron/types";
import { simulateContractHelper } from "@/helpers/walletClienHelper";
import type { BigNumber } from "ethers";

import SDEUSDSwapperAbi from "@/abis/SDEUSDSwapper";
import type { Address } from "viem";
const deUSDAddress = "0x15700B564Ca08D9439C58cA5053166E8317aa138";

const getDeUsd0xData = async (
cauldronObject: CauldronInfo,
collateralAmount: BigNumber,
Expand All @@ -12,23 +18,25 @@ const getDeUsd0xData = async (
//@ts-ignore
const { mim, liquidationSwapper, collateral } = cauldronObject.contracts;

const response = await swap0xRequestV2(
const { result } = await simulateContractHelper({
address: liquidationSwapper!.address,
abi: SDEUSDSwapperAbi,
functionName: "previewSDEUSDOut",
args: [collateralAmount],
});

const deUSDAmount = result;

const response = await swapOdosRequest(
cauldronObject.config.chainId,
mim.address,
collateral.address,
mim.address as Address,
deUSDAddress as Address,
slipage,
// @ts-ignore
collateralAmount,
liquidationSwapper!.address
deUSDAmount,
liquidationSwapper!.address as Address
);

// @ts-ignore
const liquidityAvailable = response.response.liquidityAvailable;

if (!liquidityAvailable) {
throw new Error("Not enough liquidity available");
}

return utils.defaultAbiCoder.encode(
["address", "bytes"],
// @ts-ignore
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { utils } from "ethers";
import { swapOdosRequest } from "@/helpers/odos";

import type { CauldronInfo } from "@/helpers/cauldron/types";
import type { BigNumber } from "ethers";
import type { Address } from "viem";

const deUSDAddress = "0x15700B564Ca08D9439C58cA5053166E8317aa138";

const fetchLevSdeusdSwapData = async (
cauldronObject: CauldronInfo,
collateralAmount: BigNumber,
slipage: number
) => {
// @ts-ignore
const { mim, leverageSwapper } = cauldronObject.contracts;

const buyToken = deUSDAddress;

const swapResponse = await swapOdosRequest(
cauldronObject.config.chainId,
buyToken,
mim.address as Address,
slipage,
// @ts-ignore
collateralAmount,
leverageSwapper!.address as Address
);

return utils.defaultAbiCoder.encode(
["address", "bytes"],
// @ts-ignore
[swapResponse.to, swapResponse.data]
);
};

export default fetchLevSdeusdSwapData;
22 changes: 2 additions & 20 deletions src/helpers/cauldron/cook/0xSwapData/leverage/getLev0xData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { fetchLev0xData, fetchLev0xDataV2 } from "./fetchLev0xData";
import { fetchLevOdosData } from "./fetchLevOdosData";

import getVelodrome0xData from "./getVelodrome0xData";
import fetchLevSdeusdSwapData from "./fetchLevSdeusdSwapData";

const apeAddress = "0x4d224452801ACEd8B2F0aebE155379bb5D594381";
const usdtAddress = "0xdAC17F958D2ee523a2206206994597C13D831ec7";
const wethAddress = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
const deUSDAddress = "0x15700B564Ca08D9439C58cA5053166E8317aa138";

import type { CauldronInfo } from "@/helpers/cauldron/types";
import type { BigNumber } from "ethers";
Expand Down Expand Up @@ -40,25 +40,7 @@ const getLev0xData = async (
return await fetchLev0xData(cauldronObject, amount, slipage, wethAddress);

if (iStdeUSD) {
const response = await fetchLev0xDataV2(
cauldronObject,
amount,
slipage,
deUSDAddress
);

// @ts-ignore
const liquidityAvailable = response.response.liquidityAvailable;

if (!liquidityAvailable) {
throw new Error("Not enough liquidity available");
}

return utils.defaultAbiCoder.encode(
["address", "bytes"],
// @ts-ignore
[response.to, response.data]
);
return await fetchLevSdeusdSwapData(cauldronObject, amount, slipage);
}

if (isCvxTricrypto || isCvx3pool) {
Expand Down

0 comments on commit c8b9d10

Please sign in to comment.