Skip to content

Commit

Permalink
Refactoring code
Browse files Browse the repository at this point in the history
  • Loading branch information
pgbrandao committed Nov 25, 2023
1 parent 313f107 commit d7f2958
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 73 deletions.
22 changes: 11 additions & 11 deletions core/src/asset-strategies/AaveV3DepositStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getMagicOffsets } from "core/src/utils/get-magic-offset";
import { IERC20, IPool } from "core/src/abis";
import {
FRACTION_MULTIPLIER,
MAGIC_REPLACER_0,
MAGIC_REPLACERS,
} from "core/src/utils/get-magic-offset";
import {
FetchPriceDataParams,
Expand Down Expand Up @@ -91,9 +91,9 @@ export class AaveV3DepositStrategy extends InterfaceStrategy {
getMagicOffsets({
data: IERC20.encodeFunctionData("approve", [
poolAddress,
MAGIC_REPLACER_0,
MAGIC_REPLACERS[0],
]),
magicReplacers: [MAGIC_REPLACER_0],
magicReplacers: [MAGIC_REPLACERS[0]],
});

routerOperation.steps.push({
Expand All @@ -110,8 +110,8 @@ export class AaveV3DepositStrategy extends InterfaceStrategy {
});

const { offsets: balanceOfToOffsets } = getMagicOffsets({
data: IERC20.encodeFunctionResult("balanceOf", [MAGIC_REPLACER_0]),
magicReplacers: [MAGIC_REPLACER_0],
data: IERC20.encodeFunctionResult("balanceOf", [MAGIC_REPLACERS[0]]),
magicReplacers: [MAGIC_REPLACERS[0]],
});

routerOperation.steps.push({
Expand All @@ -133,11 +133,11 @@ export class AaveV3DepositStrategy extends InterfaceStrategy {
getMagicOffsets({
data: IPool.encodeFunctionData("supply", [
linkedAsset.address, // asset
MAGIC_REPLACER_0, // amount
MAGIC_REPLACERS[0], // amount
walletAddress, // onBehalfOf
0, // referralCode
]),
magicReplacers: [MAGIC_REPLACER_0],
magicReplacers: [MAGIC_REPLACERS[0]],
});

routerOperation.steps.push({
Expand Down Expand Up @@ -202,15 +202,15 @@ export class AaveV3DepositStrategy extends InterfaceStrategy {
getMagicOffsets({
data: IPool.encodeFunctionData("withdraw", [
linkedAsset.address, // asset
MAGIC_REPLACER_0, // _shares
MAGIC_REPLACERS[0], // _shares
walletAddress, // to
]),
magicReplacers: [MAGIC_REPLACER_0],
magicReplacers: [MAGIC_REPLACERS[0]],
});

const { offsets: withdrawToOffsets } = getMagicOffsets({
data: IPool.encodeFunctionResult("withdraw", [MAGIC_REPLACER_0]),
magicReplacers: [MAGIC_REPLACER_0],
data: IPool.encodeFunctionResult("withdraw", [MAGIC_REPLACERS[0]]),
magicReplacers: [MAGIC_REPLACERS[0]],
});

routerOperation.steps.push({
Expand Down
19 changes: 8 additions & 11 deletions core/src/asset-strategies/BalancerDepositStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ import {
getPrice,
} from "../transaction/asset-type-strategies-helpers";
import {
FRACTION_MULTIPLIER,
MAGIC_REPLACERS,
getMagicOffsets,
} from "core/src/utils/get-magic-offset";
import { IComposableStablePool, IERC20, IVault } from "core/src/abis";
import {
FRACTION_MULTIPLIER,
MAGIC_REPLACER_0,
} from "core/src/utils/get-magic-offset";
import {
FetchPriceDataParams,
GetPriceParams,
Expand Down Expand Up @@ -273,9 +270,9 @@ export class BalancerDepositStrategy extends InterfaceStrategy {
getMagicOffsets({
data: IERC20.encodeFunctionData("approve", [
vaultAddress,
MAGIC_REPLACER_0,
MAGIC_REPLACERS[0],
]),
magicReplacers: [MAGIC_REPLACER_0],
magicReplacers: [MAGIC_REPLACERS[0]],
});
routerOperation.steps.push({
stepAddress: linkedAsset.address,
Expand All @@ -294,8 +291,8 @@ export class BalancerDepositStrategy extends InterfaceStrategy {
}

const { offsets: balanceOfToOffsets } = getMagicOffsets({
data: IERC20.encodeFunctionResult("balanceOf", [MAGIC_REPLACER_0]),
magicReplacers: [MAGIC_REPLACER_0],
data: IERC20.encodeFunctionResult("balanceOf", [MAGIC_REPLACERS[0]]),
magicReplacers: [MAGIC_REPLACERS[0]],
});
routerOperation.steps.push({
stepAddress: asset.address,
Expand Down Expand Up @@ -447,8 +444,8 @@ export class BalancerDepositStrategy extends InterfaceStrategy {
});

const { offsets: balanceOfToOffsets } = getMagicOffsets({
data: IERC20.encodeFunctionResult("balanceOf", [MAGIC_REPLACER_0]),
magicReplacers: [MAGIC_REPLACER_0],
data: IERC20.encodeFunctionResult("balanceOf", [MAGIC_REPLACERS[0]]),
magicReplacers: [MAGIC_REPLACERS[0]],
});

asset.linkedAssets.map((la, i) => {
Expand Down Expand Up @@ -511,7 +508,7 @@ export class BalancerDepositStrategy extends InterfaceStrategy {
false, // fromInternalBalance
],
]),
magicReplacers: [MAGIC_REPLACERS[0]], // Each replacer appear once in amounts and once in userData.
magicReplacers: [MAGIC_REPLACERS[0]],
});

routerOperation.steps.push({
Expand Down
22 changes: 11 additions & 11 deletions core/src/asset-strategies/BeefyDepositStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getMagicOffsets } from "core/src/utils/get-magic-offset";
import { IBeefyVaultV6, IERC20 } from "core/src/abis";
import {
FRACTION_MULTIPLIER,
MAGIC_REPLACER_0,
MAGIC_REPLACERS,
} from "core/src/utils/get-magic-offset";
import {
FetchPriceDataParams,
Expand Down Expand Up @@ -108,9 +108,9 @@ export class BeefyDepositStrategy extends InterfaceStrategy {
getMagicOffsets({
data: IERC20.encodeFunctionData("approve", [
asset.address,
MAGIC_REPLACER_0,
MAGIC_REPLACERS[0],
]),
magicReplacers: [MAGIC_REPLACER_0],
magicReplacers: [MAGIC_REPLACERS[0]],
});

routerOperation.steps.push({
Expand All @@ -127,8 +127,8 @@ export class BeefyDepositStrategy extends InterfaceStrategy {
});

const { offsets: balanceOfToOffsets } = getMagicOffsets({
data: IERC20.encodeFunctionResult("balanceOf", [MAGIC_REPLACER_0]),
magicReplacers: [MAGIC_REPLACER_0],
data: IERC20.encodeFunctionResult("balanceOf", [MAGIC_REPLACERS[0]]),
magicReplacers: [MAGIC_REPLACERS[0]],
});

routerOperation.steps.push({
Expand All @@ -149,9 +149,9 @@ export class BeefyDepositStrategy extends InterfaceStrategy {
const { data: depositEncodedCall, offsets: depositFromOffsets } =
getMagicOffsets({
data: IBeefyVaultV6.encodeFunctionData("deposit", [
MAGIC_REPLACER_0, // _amount
MAGIC_REPLACERS[0], // _amount
]),
magicReplacers: [MAGIC_REPLACER_0],
magicReplacers: [MAGIC_REPLACERS[0]],
});

routerOperation.steps.push({
Expand Down Expand Up @@ -216,8 +216,8 @@ export class BeefyDepositStrategy extends InterfaceStrategy {
});

const { offsets: balanceOfToOffsets } = getMagicOffsets({
data: IERC20.encodeFunctionResult("balanceOf", [MAGIC_REPLACER_0]),
magicReplacers: [MAGIC_REPLACER_0],
data: IERC20.encodeFunctionResult("balanceOf", [MAGIC_REPLACERS[0]]),
magicReplacers: [MAGIC_REPLACERS[0]],
});

routerOperation.steps.push({
Expand All @@ -238,9 +238,9 @@ export class BeefyDepositStrategy extends InterfaceStrategy {
const { data: withdrawEncodedCall, offsets: withdrawFromOffsets } =
getMagicOffsets({
data: IBeefyVaultV6.encodeFunctionData("withdraw", [
MAGIC_REPLACER_0, // _shares
MAGIC_REPLACERS[0], // _shares
]),
magicReplacers: [MAGIC_REPLACER_0],
magicReplacers: [MAGIC_REPLACERS[0]],
});

routerOperation.steps.push({
Expand Down
37 changes: 18 additions & 19 deletions core/src/asset-strategies/GammaDepositStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import {
} from "core/src/abis";
import {
FRACTION_MULTIPLIER,
MAGIC_REPLACER_0,
MAGIC_REPLACER_1,
MAGIC_REPLACERS,
} from "core/src/utils/get-magic-offset";
import { loadConfig } from "../config/load-config";
import {
Expand Down Expand Up @@ -186,18 +185,18 @@ export class GammaDepositStrategy extends InterfaceStrategy {
} = getMagicOffsets({
data: GammaRatiosCalculator.encodeFunctionData("calculateRatios", [
[linkedAssetAddresses[0], linkedAssetAddresses[1]],
[MAGIC_REPLACER_0, MAGIC_REPLACER_1],
[MAGIC_REPLACERS[0], MAGIC_REPLACERS[1]],
asset.address,
hypervisorRouterAddress, // hypervisorRouterAddress
]),
magicReplacers: [MAGIC_REPLACER_0, MAGIC_REPLACER_1],
magicReplacers: [MAGIC_REPLACERS[0], MAGIC_REPLACERS[1]],
});
const { offsets: calculateRatiosToOffsets } = getMagicOffsets({
data: GammaRatiosCalculator.encodeFunctionResult("calculateRatios", [
MAGIC_REPLACER_0,
MAGIC_REPLACER_1,
MAGIC_REPLACERS[0],
MAGIC_REPLACERS[1],
]),
magicReplacers: [MAGIC_REPLACER_0, MAGIC_REPLACER_1],
magicReplacers: [MAGIC_REPLACERS[0], MAGIC_REPLACERS[1]],
});

routerOperation.steps.push({
Expand Down Expand Up @@ -238,9 +237,9 @@ export class GammaDepositStrategy extends InterfaceStrategy {
getMagicOffsets({
data: IERC20.encodeFunctionData("approve", [
asset.address,
MAGIC_REPLACER_0,
MAGIC_REPLACERS[0],
]),
magicReplacers: [MAGIC_REPLACER_0],
magicReplacers: [MAGIC_REPLACERS[0]],
});

routerOperation.steps.push({
Expand All @@ -260,20 +259,20 @@ export class GammaDepositStrategy extends InterfaceStrategy {
const { data: depositEncodedCall, offsets: depositFromOffsets } =
getMagicOffsets({
data: IHypervisorRouter.encodeFunctionData("deposit", [
MAGIC_REPLACER_0,
MAGIC_REPLACER_1,
MAGIC_REPLACERS[0],
MAGIC_REPLACERS[1],
walletAddress,
asset.address,
[0, 0, 0, 0], // minIn
]),
magicReplacers: [MAGIC_REPLACER_0, MAGIC_REPLACER_1],
magicReplacers: [MAGIC_REPLACERS[0], MAGIC_REPLACERS[1]],
});

const { offsets: depositToOffsets } = getMagicOffsets({
data: IHypervisorRouter.encodeFunctionResult("deposit", [
MAGIC_REPLACER_0,
MAGIC_REPLACERS[0],
]),
magicReplacers: [MAGIC_REPLACER_0],
magicReplacers: [MAGIC_REPLACERS[0]],
});

routerOperation.steps.push({
Expand Down Expand Up @@ -345,20 +344,20 @@ export class GammaDepositStrategy extends InterfaceStrategy {
const { data: withdrawEncodedCall, offsets: withdrawFromOffsets } =
getMagicOffsets({
data: IHypervisor.encodeFunctionData("withdraw", [
MAGIC_REPLACER_0,
MAGIC_REPLACERS[0],
walletAddress,
walletAddress,
[0, 0, 0, 0], // minAmounts
]),
magicReplacers: [MAGIC_REPLACER_0],
magicReplacers: [MAGIC_REPLACERS[0]],
});

const { offsets: withdrawToOffsets } = getMagicOffsets({
data: IHypervisor.encodeFunctionResult("withdraw", [
MAGIC_REPLACER_0,
MAGIC_REPLACER_1,
MAGIC_REPLACERS[0],
MAGIC_REPLACERS[1],
]),
magicReplacers: [MAGIC_REPLACER_0, MAGIC_REPLACER_1],
magicReplacers: [MAGIC_REPLACERS[0], MAGIC_REPLACERS[1]],
});

routerOperation.steps.push({
Expand Down
Loading

0 comments on commit d7f2958

Please sign in to comment.