Skip to content

Commit

Permalink
Parametrized clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
uncoolzero committed Sep 12, 2023
1 parent 21deb0a commit 24552e6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
14 changes: 12 additions & 2 deletions projects/sdk/src/lib/farm/LibraryPresets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,20 @@ export class LibraryPresets {
const addLiquidity = new sdk.farm.actions.WellSync(well, tokenIn, recipient);

// This approves the transferToBeanstalk operation.
const approveBack = new sdk.farm.actions.ApproveERC20(well.lpToken, sdk.contracts.beanstalk.address, true);
const approveClipboard = {
tag: "amountToDeposit",
copySlot: 0,
pasteSlot: 1
}
const approveBack = new sdk.farm.actions.ApproveERC20(well.lpToken, sdk.contracts.beanstalk.address, approveClipboard);

// Transfers the output token back to Beanstalk, from PIPELINE.
const transferToBeanstalk = new sdk.farm.actions.TransferToken(well.address, account, FarmFromMode.EXTERNAL, FarmToMode.INTERNAL, true);
const transferClipboard = {
tag: "amountToDeposit",
copySlot: 0,
pasteSlot: 2
}
const transferToBeanstalk = new sdk.farm.actions.TransferToken(well.address, account, FarmFromMode.EXTERNAL, FarmToMode.INTERNAL, transferClipboard);


result.push(transfer);
Expand Down
10 changes: 5 additions & 5 deletions projects/sdk/src/lib/farm/actions/ApproveERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ export class ApproveERC20 extends StepClass<AdvancedPipePreparedResult> {
public name: string = "approve";
public token: ERC20Token;
public spender: string;
public useClipboard?: boolean;
public clipboard?: { tag: string, copySlot: number, pasteSlot: number };

constructor(token: ERC20Token, spender: string, useClipboard?: boolean) {
constructor(token: ERC20Token, spender: string, clipboard?: { tag: string, copySlot: number, pasteSlot: number }) {
super();
if (!token) throw new Error("ApproveERC20 action requires a token");
if (!spender) throw new Error("ApproveERC20 action requires a spender");

this.token = token;
this.spender = spender;
this.useClipboard = useClipboard;
this.clipboard = clipboard;
}

async run(_amountInStep: ethers.BigNumber, context: RunContext): Promise<Step<AdvancedPipePreparedResult>> {
Expand All @@ -30,12 +30,12 @@ export class ApproveERC20 extends StepClass<AdvancedPipePreparedResult> {
token: this.token,
spender: this.spender,
amountInStep: _amountInStep,
useClipboard: this.useClipboard
clipboard: this.clipboard
});
return {
target: this.token.address,
callData: this.token.getContract().interface.encodeFunctionData("approve", [this.spender, _amountInStep]),
clipboard: this.useClipboard ? Clipboard.encodeSlot(context.step.findTag("amountToDeposit"), 0, 1) : undefined
clipboard: this.clipboard ? Clipboard.encodeSlot(context.step.findTag(this.clipboard.tag), this.clipboard.copySlot, this.clipboard.pasteSlot) : undefined
};
},
decode: (data: string) => this.token.getContract().interface.decodeFunctionData("approve", data),
Expand Down
8 changes: 5 additions & 3 deletions projects/sdk/src/lib/farm/actions/Deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { Clipboard } from "src/lib/depot";

export class Deposit extends StepClass<BasicPreparedResult> {
public name: string = "deposit";
public clipboard?: { tag: string, copySlot: number, pasteSlot: number };

constructor(public readonly token: Token, public readonly fromMode: FarmFromMode = FarmFromMode.INTERNAL_EXTERNAL) {
constructor(public readonly token: Token, public readonly fromMode: FarmFromMode = FarmFromMode.INTERNAL_EXTERNAL, clipboard?: { tag: string, copySlot: number, pasteSlot: number }) {
super();
this.clipboard = clipboard;
}

async run(_amountInStep: ethers.BigNumber, context: RunContext) {
Expand All @@ -20,18 +22,18 @@ export class Deposit extends StepClass<BasicPreparedResult> {
token: this.token.symbol,
amountInStep: _amountInStep,
fromMode: this.fromMode,
clipboard: this.clipboard,
context
});
if (!_amountInStep) throw new Error("Deposit: Missing _amountInStep");
const wellDeposit = this.token.symbol === "BEANETH";
return {
target: Deposit.sdk.contracts.beanstalk.address,
callData: Deposit.sdk.contracts.beanstalk.interface.encodeFunctionData("deposit", [
this.token.address,
_amountInStep,
this.fromMode
]),
clipboard: wellDeposit ? Clipboard.encodeSlot(context.step.findTag("depositAmount"), 6, 1) : undefined
clipboard: this.clipboard ? Clipboard.encodeSlot(context.step.findTag(this.clipboard.tag), this.clipboard.copySlot, this.clipboard.pasteSlot) : undefined
};
},
decode: (data: string) => Deposit.sdk.contracts.beanstalk.interface.decodeFunctionData("deposit", data),
Expand Down
10 changes: 5 additions & 5 deletions projects/sdk/src/lib/farm/actions/TransferToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { Clipboard } from "src/lib/depot";

export class TransferToken extends StepClass<BasicPreparedResult> {
public name: string = "transferToken";
public useClipboard?: boolean;
public clipboard?: { tag: string, copySlot: number, pasteSlot: number };

constructor(
public readonly _tokenIn: string,
public readonly _recipient: string,
public readonly _fromMode: FarmFromMode = FarmFromMode.INTERNAL_TOLERANT,
public readonly _toMode: FarmToMode = FarmToMode.INTERNAL,
useClipboard?: boolean
clipboard?: { tag: string, copySlot: number, pasteSlot: number }
) {
super();
this.useClipboard = useClipboard;
this.clipboard = clipboard;
}

async run(_amountInStep: ethers.BigNumber, context: RunContext) {
Expand All @@ -29,7 +29,7 @@ export class TransferToken extends StepClass<BasicPreparedResult> {
amountInStep: _amountInStep,
fromMode: this._fromMode,
toMode: this._toMode,
useClipboard: this.useClipboard
clipboard: this.clipboard
});
return {
target: TransferToken.sdk.contracts.beanstalk.address,
Expand All @@ -40,7 +40,7 @@ export class TransferToken extends StepClass<BasicPreparedResult> {
this._fromMode, //
this._toMode //
]),
clipboard: this.useClipboard ? Clipboard.encodeSlot(context.step.findTag("amountToDeposit"), 0, 2) : undefined
clipboard: this.clipboard ? Clipboard.encodeSlot(context.step.findTag(this.clipboard.tag), this.clipboard.copySlot, this.clipboard.pasteSlot) : undefined
};
},
decode: (data: string) => TransferToken.sdk.contracts.beanstalk.interface.decodeFunctionData("transferToken", data),
Expand Down
8 changes: 7 additions & 1 deletion projects/sdk/src/lib/silo/depositGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ export const getDepositGraph = (sdk: BeanstalkSDK): Graph => {
for (const token of sdk.tokens.siloWhitelist) {
const from = token.symbol;
const to = `${from}:SILO`;
const useClipboard = token.equals(sdk.tokens.BEAN_ETH_WELL_LP);
const beanEthClipboard = {
tag: "depositAmount",
copySlot: 6,
pasteSlot: 1
};
graph.setEdge(from, to, {
build: (_: string, fromMode: FarmFromMode, toMode: FarmToMode) => new sdk.farm.actions.Deposit(token, fromMode),
build: (_: string, fromMode: FarmFromMode, toMode: FarmToMode) => new sdk.farm.actions.Deposit(token, fromMode, useClipboard ? beanEthClipboard : undefined),
from,
to,
label: "deposit"
Expand Down

0 comments on commit 24552e6

Please sign in to comment.