Skip to content

Commit

Permalink
add minimum output userarg
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmDreamy committed Dec 29, 2024
1 parent 2688134 commit dbff57a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions scripts/create-magicusd0pp-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const main = async () => {
usualApiEndpoint: "https://app.usual.money/api",
odosApiEndpoint: "https://api.odos.xyz",
slippageLimitPercent: 0.1,
minimumSwapUsd: 1000,
},
},
{},
Expand Down
17 changes: 12 additions & 5 deletions web3-functions/magicusd0pp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const HARVESTER_ABI = parseAbi([
]);

const USUAL_DISTRIBUTION_CHALLENGE_PERIOD = 604800n; // 1 week
const WAD = 10n ** 18n;

type MagicUsd0ppUserArgs = {
distributionAddress: Address;
Expand All @@ -39,6 +40,7 @@ type MagicUsd0ppUserArgs = {
usualApiEndpoint: string;
odosApiEndpoint: string;
slippageLimitPercent: number;
minimumSwapUsd: number;
};

type OffChainDistribution = {
Expand All @@ -60,6 +62,7 @@ Web3Function.onRun(
usualApiEndpoint,
odosApiEndpoint,
slippageLimitPercent,
minimumSwapUsd,
} = userArgs as MagicUsd0ppUserArgs;

const client = createJsonRpcPublicClient(multiChainProvider.default());
Expand Down Expand Up @@ -101,10 +104,6 @@ Web3Function.onRun(
.json<Array<OffChainDistribution>>(),
]);

if (distributions.length === 0) {
return { canExec: false, message: "No distributions" };
}

const currentTimestamp = BigInt(Math.floor(Date.now() / 1000));
let pendingDistribution:
| (typeof offChainDistributionQueue)[number]
Expand Down Expand Up @@ -170,6 +169,14 @@ Web3Function.onRun(
slippageLimitPercent,
disableRFQs: true,
});

if (quote.netOutValue < minimumSwapUsd) {
return {
canExec: false,
message: "Insufficient swap output",
};
}

callData.push({
to: harvesterAddress,
data: encodeFunctionData({
Expand All @@ -178,7 +185,7 @@ Web3Function.onRun(
args: [
quote.transaction.to,
quote.transaction.data,
(quote.outputTokens[0].amount * parseEther("1")) /
(quote.outputTokens[0].amount * WAD) /
parseEther(`${(100 - slippageLimitPercent) / 100}`),
],
}),
Expand Down
3 changes: 2 additions & 1 deletion web3-functions/magicusd0pp/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"usualAddress": "string",
"usualApiEndpoint": "string",
"odosApiEndpoint": "string",
"slippageLimitPercent": "number"
"slippageLimitPercent": "number",
"minimumSwapUsd": "number"
}
}
3 changes: 2 additions & 1 deletion web3-functions/magicusd0pp/userArgs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"usualAddress": "0xC4441c2BE5d8fA8126822B9929CA0b81Ea0DE38E",
"usualApiEndpoint": "https://app.usual.money/api",
"odosApiEndpoint": "https://api.odos.xyz",
"slippageLimitPercent": 0.1
"slippageLimitPercent": 0.1,
"minimumSwapUsd": 1000
}

0 comments on commit dbff57a

Please sign in to comment.