From dbff57a7208e1ba51e1da49d303ab69c1c67f212 Mon Sep 17 00:00:00 2001 From: 0xmDreamy <0xmDreamy@proton.me> Date: Sun, 29 Dec 2024 12:36:20 +0100 Subject: [PATCH] add minimum output userarg --- scripts/create-magicusd0pp-task.ts | 1 + web3-functions/magicusd0pp/index.ts | 17 ++++++++++++----- web3-functions/magicusd0pp/schema.json | 3 ++- web3-functions/magicusd0pp/userArgs.json | 3 ++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/scripts/create-magicusd0pp-task.ts b/scripts/create-magicusd0pp-task.ts index 3d07b14..7db6d28 100644 --- a/scripts/create-magicusd0pp-task.ts +++ b/scripts/create-magicusd0pp-task.ts @@ -36,6 +36,7 @@ const main = async () => { usualApiEndpoint: "https://app.usual.money/api", odosApiEndpoint: "https://api.odos.xyz", slippageLimitPercent: 0.1, + minimumSwapUsd: 1000, }, }, {}, diff --git a/web3-functions/magicusd0pp/index.ts b/web3-functions/magicusd0pp/index.ts index bdceae7..985c57e 100644 --- a/web3-functions/magicusd0pp/index.ts +++ b/web3-functions/magicusd0pp/index.ts @@ -29,6 +29,7 @@ const HARVESTER_ABI = parseAbi([ ]); const USUAL_DISTRIBUTION_CHALLENGE_PERIOD = 604800n; // 1 week +const WAD = 10n ** 18n; type MagicUsd0ppUserArgs = { distributionAddress: Address; @@ -39,6 +40,7 @@ type MagicUsd0ppUserArgs = { usualApiEndpoint: string; odosApiEndpoint: string; slippageLimitPercent: number; + minimumSwapUsd: number; }; type OffChainDistribution = { @@ -60,6 +62,7 @@ Web3Function.onRun( usualApiEndpoint, odosApiEndpoint, slippageLimitPercent, + minimumSwapUsd, } = userArgs as MagicUsd0ppUserArgs; const client = createJsonRpcPublicClient(multiChainProvider.default()); @@ -101,10 +104,6 @@ Web3Function.onRun( .json>(), ]); - if (distributions.length === 0) { - return { canExec: false, message: "No distributions" }; - } - const currentTimestamp = BigInt(Math.floor(Date.now() / 1000)); let pendingDistribution: | (typeof offChainDistributionQueue)[number] @@ -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({ @@ -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}`), ], }), diff --git a/web3-functions/magicusd0pp/schema.json b/web3-functions/magicusd0pp/schema.json index 0dfabca..32bfaa3 100644 --- a/web3-functions/magicusd0pp/schema.json +++ b/web3-functions/magicusd0pp/schema.json @@ -11,6 +11,7 @@ "usualAddress": "string", "usualApiEndpoint": "string", "odosApiEndpoint": "string", - "slippageLimitPercent": "number" + "slippageLimitPercent": "number", + "minimumSwapUsd": "number" } } diff --git a/web3-functions/magicusd0pp/userArgs.json b/web3-functions/magicusd0pp/userArgs.json index bd785b8..bce1c0d 100644 --- a/web3-functions/magicusd0pp/userArgs.json +++ b/web3-functions/magicusd0pp/userArgs.json @@ -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 }