Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,5 @@ export interface IConfig {
tokenListStrategy: "explorer" | "chain";
lookbackRange: number;
confirmDrip: boolean;
leaveDust: BigNumber;
}
2 changes: 1 addition & 1 deletion ts/drip/dripItAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function dripItAll(
tokensToSwap.map((token) => ({
symbol: token.symbol,
address: token.address,
balance: formatUnits(token.balance, token.decimals),
balance: formatUnits(token.adjustedBalance, token.decimals),
buyAmount: formatUnits(token.buyAmount, WETH_DECIMALS),
needsApproval: token.needsApproval,
}))
Expand Down
6 changes: 3 additions & 3 deletions ts/drip/getTokensToSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getAllowances } from "./getAllowances";

export interface GetTokensToSwapResult {
buyAmount: BigNumber;
balance: BigNumber;
adjustedBalance: BigNumber;
allowance: BigNumber;
needsApproval: boolean;
address: string;
Expand Down Expand Up @@ -45,7 +45,7 @@ export async function getTokensToSwap(
// minValue filter again with _real_ balance
const unfilteredWithBalanceAndAllowance = unfiltered.map((token, idx) => ({
...token,
balance: balances[idx],
adjustedBalance: balances[idx].sub(config.leaveDust),
allowance: allowances[idx],
needsApproval: allowances[idx].lt(balances[idx]),
}));
Expand All @@ -56,7 +56,7 @@ export async function getTokensToSwap(
unfilteredWithBalanceAndAllowance.map((token) =>
orderBookApi.getQuote({
sellToken: token.address,
sellAmountBeforeFee: token.balance.toString(),
sellAmountBeforeFee: token.adjustedBalance.toString(),
kind: OrderQuoteSideKindSell.SELL,
buyToken: config.wrappedNativeToken,
from: config.gpv2Settlement,
Expand Down
2 changes: 1 addition & 1 deletion ts/drip/postOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function postOrders(
orderBookApi.sendOrder({
sellToken: token.address,
buyToken: config.wrappedNativeToken,
sellAmount: token.balance.toString(),
sellAmount: token.adjustedBalance.toString(),
buyAmount: token.buyAmount.toString(),
validTo: nextValidTo,
appData: appDataContent,
Expand Down
2 changes: 1 addition & 1 deletion ts/drip/swapTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const swapTokens = async (

const toDrip = toActuallySwap.map((token) => ({
token: token.address,
sellAmount: token.balance,
sellAmount: token.adjustedBalance,
buyAmount: token.buyAmount,
}));

Expand Down
10 changes: 10 additions & 0 deletions ts/utils/readConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ export async function readConfig(): Promise<
"-c, --confirm-drip",
"Ask for confirmation before dripping"
).default(false)
)
.addOption(
new Option(
"--leave-dust <wei>",
"Amount of each token (in wei) to leave in the contract after swapping"
)
.default(BigNumber.from(10))
.argParser((x) => BigNumber.from(x))
);

program.parse();
Expand All @@ -88,6 +96,7 @@ export async function readConfig(): Promise<
lookbackRange,
tokenListStrategy,
confirmDrip,
leaveDust,
} = options;
const network = selectedNetwork || "mainnet";

Expand Down Expand Up @@ -147,6 +156,7 @@ export async function readConfig(): Promise<
lookbackRange,
targetSafe,
confirmDrip,
leaveDust,
},
provider,
];
Expand Down
Loading