From 268813446f7268a8dbe8973ee94e8481b42db5a3 Mon Sep 17 00:00:00 2001 From: 0xmDreamy <0xmDreamy@proton.me> Date: Sat, 28 Dec 2024 11:25:28 +0100 Subject: [PATCH 1/8] feat(magicusd0pp): Harvest USUAL rewards --- scripts/create-magicusd0pp-task.ts | 11 +- utils/odos.ts | 80 ++++++++++ web3-functions/magicusd0pp/index.ts | 182 ++++++++++++++++++----- web3-functions/magicusd0pp/schema.json | 9 +- web3-functions/magicusd0pp/userArgs.json | 11 +- 5 files changed, 246 insertions(+), 47 deletions(-) create mode 100644 utils/odos.ts diff --git a/scripts/create-magicusd0pp-task.ts b/scripts/create-magicusd0pp-task.ts index cbc15e7..3d07b14 100644 --- a/scripts/create-magicusd0pp-task.ts +++ b/scripts/create-magicusd0pp-task.ts @@ -21,16 +21,21 @@ const main = async () => { const { tx } = await automate.prepareBatchExecTask( { - name: "MagicUSD0pp Off-Chain Distribution Claimer", + name: "MagicUSD0pp Handler", web3FunctionHash: cid, trigger: { type: TriggerType.TIME, interval: THIRTY_SECONDS, }, web3FunctionArgs: { - execAddress: "0x75cC0C0DDD2Ccafe6EC415bE686267588011E36A", - usualApiEndpoint: "https://app.usual.money/api/rewards", + distributionAddress: "0x75cC0C0DDD2Ccafe6EC415bE686267588011E36A", + harvesterAddress: "0x0F9af7168CC8819ce3066867509a7F9170fb108B", magicUsd0ppAddress: "0x73075fD1522893D9dC922991542f98F08F2c1C99", + usd0ppAddress: "0x35D8949372D46B7a3D5A56006AE77B215fc69bC0", + usualAddress: "0xC4441c2BE5d8fA8126822B9929CA0b81Ea0DE38E", + usualApiEndpoint: "https://app.usual.money/api", + odosApiEndpoint: "https://api.odos.xyz", + slippageLimitPercent: 0.1, }, }, {}, diff --git a/utils/odos.ts b/utils/odos.ts new file mode 100644 index 0000000..da8044e --- /dev/null +++ b/utils/odos.ts @@ -0,0 +1,80 @@ +import ky from "ky"; +import * as R from "remeda"; +import type { Address, Hex } from "viem"; + +export type OdosQuoteParameters = { + endpoint: string; + chainId: number; + inputTokens: Array<{ tokenAddress: Address; amount: bigint }>; + outputTokens: Array<{ tokenAddress: Address; proportion: number }>; + userAddr: Address; + slippageLimitPercent?: number; + disableRFQs?: boolean; + compact?: boolean; + simple?: boolean; +}; + +export async function odosQuote(quoteParameters: OdosQuoteParameters) { + const odosApi = ky.extend({ + prefixUrl: quoteParameters.endpoint, + }); + + const { pathId } = await odosApi + .post("sor/quote/v2", { + json: { + ...R.omit(quoteParameters, ["endpoint"]), + inputTokens: quoteParameters.inputTokens.map( + ({ tokenAddress, amount }) => ({ + tokenAddress, + amount: amount.toString(), + }), + ), + }, + }) + .json<{ pathId: string }>(); + + const assembledQuote = await odosApi + .post("sor/assemble", { + json: { + pathId, + userAddr: quoteParameters.userAddr, + }, + }) + .json<{ + blockNumber: number; + gasEstimate: number; + gasEstimateValue: number; + inputTokens: Array<{ tokenAddress: Address; amount: `${bigint}` }>; + outputTokens: Array<{ tokenAddress: Address; amount: `${bigint}` }>; + netOutValue: number; + outValues: number[]; + transaction: { + gas: number; + gasPrice: number; + value: `${bigint}`; + to: Address; + from: Address; + data: Hex; + nonce: number; + chainId: number; + }; + }>(); + + return { + ...assembledQuote, + inputTokens: assembledQuote.inputTokens.map(({ tokenAddress, amount }) => ({ + tokenAddress, + amount: BigInt(amount), + })), + outputTokens: assembledQuote.outputTokens.map( + ({ tokenAddress, amount }) => ({ + tokenAddress, + amount: BigInt(amount), + }), + ), + transaction: { + ...assembledQuote.transaction, + value: BigInt(assembledQuote.transaction.value), + }, + }; +} diff --git a/web3-functions/magicusd0pp/index.ts b/web3-functions/magicusd0pp/index.ts index 0860ddd..bdceae7 100644 --- a/web3-functions/magicusd0pp/index.ts +++ b/web3-functions/magicusd0pp/index.ts @@ -1,22 +1,44 @@ import { Web3Function, type Web3FunctionContext, - Web3FunctionResult, + type Web3FunctionResultCallData, } from "@gelatonetwork/web3-functions-sdk"; import ky from "ky"; -import { type Address, type Hex, encodeFunctionData, parseAbi } from "viem"; +import { + type Address, + type Hex, + encodeFunctionData, + erc20Abi, + parseAbi, + parseEther, +} from "viem"; +import { odosQuote } from "../../utils/odos"; import { createJsonRpcPublicClient } from "../../utils/viem"; const DISTRIBUTION_ABI = parseAbi([ "function getOffChainDistributionData() external view returns (uint256 timestamp, bytes32 merkleRoot)", "function getOffChainTokensClaimed(address account) external view returns (uint256)", + "struct QueuedOffChainDistribution { uint256 timestamp; bytes32 merkleRoot; }", + "function getOffChainDistributionQueue() external view returns (QueuedOffChainDistribution[] memory)", "function claimOffChainDistribution(address account, uint256 amount, bytes32[] calldata proof) external", + "function approveUnchallengedOffChainDistribution() external", +]); + +const HARVESTER_ABI = parseAbi([ + "function run(address router, bytes memory swapData, uint256 minAmountOut) external", ]); +const USUAL_DISTRIBUTION_CHALLENGE_PERIOD = 604800n; // 1 week + type MagicUsd0ppUserArgs = { - execAddress: Address; - usualApiEndpoint: string; + distributionAddress: Address; + harvesterAddress: Address; magicUsd0ppAddress: Address; + usd0ppAddress: Address; + usualAddress: Address; + usualApiEndpoint: string; + odosApiEndpoint: string; + slippageLimitPercent: number; }; type OffChainDistribution = { @@ -29,65 +51,147 @@ type OffChainDistribution = { Web3Function.onRun( async ({ userArgs, multiChainProvider }: Web3FunctionContext) => { - const { execAddress, usualApiEndpoint, magicUsd0ppAddress } = - userArgs as MagicUsd0ppUserArgs; + const { + distributionAddress, + harvesterAddress, + magicUsd0ppAddress, + usd0ppAddress, + usualAddress, + usualApiEndpoint, + odosApiEndpoint, + slippageLimitPercent, + } = userArgs as MagicUsd0ppUserArgs; const client = createJsonRpcPublicClient(multiChainProvider.default()); const usualRewardsApi = ky.extend({ - prefixUrl: new URL("rewards", new URL(usualApiEndpoint)), + prefixUrl: `${usualApiEndpoint}/rewards`, }); - const [[, currentMerkleRoot], claimedTokens, distributions] = - await Promise.all([ - client.readContract({ - abi: DISTRIBUTION_ABI, - address: execAddress, - functionName: "getOffChainDistributionData", - }), - client.readContract({ - abi: DISTRIBUTION_ABI, - address: execAddress, - functionName: "getOffChainTokensClaimed", - args: [magicUsd0ppAddress], - }), - usualRewardsApi - .get(magicUsd0ppAddress) - .json>(), - ]); + const [ + [, currentMerkleRoot], + offChainDistributionQueue, + claimedTokens, + usualBalance, + distributions, + ] = await Promise.all([ + client.readContract({ + abi: DISTRIBUTION_ABI, + address: distributionAddress, + functionName: "getOffChainDistributionData", + }), + client.readContract({ + abi: DISTRIBUTION_ABI, + address: distributionAddress, + functionName: "getOffChainDistributionQueue", + }), + client.readContract({ + abi: DISTRIBUTION_ABI, + address: distributionAddress, + functionName: "getOffChainTokensClaimed", + args: [magicUsd0ppAddress], + }), + client.readContract({ + abi: erc20Abi, + address: usualAddress, + functionName: "balanceOf", + args: [magicUsd0ppAddress], + }), + usualRewardsApi + .get(magicUsd0ppAddress) + .json>(), + ]); if (distributions.length === 0) { return { canExec: false, message: "No distributions" }; } + const currentTimestamp = BigInt(Math.floor(Date.now() / 1000)); + let pendingDistribution: + | (typeof offChainDistributionQueue)[number] + | undefined = undefined; + for (const distribution of offChainDistributionQueue) { + if ( + currentTimestamp >= + distribution.timestamp + USUAL_DISTRIBUTION_CHALLENGE_PERIOD && + distribution.timestamp > (pendingDistribution?.timestamp ?? 0n) + ) { + pendingDistribution = distribution; + } + } + + const distributionMerkleRoot = + pendingDistribution?.merkleRoot ?? currentMerkleRoot; const currentDistribution = distributions.find( ({ merkleRoot }) => - merkleRoot.toLowerCase() === currentMerkleRoot.toLowerCase(), + merkleRoot.toLowerCase() === distributionMerkleRoot.toLowerCase(), ); - if (currentDistribution === undefined) { - return { canExec: false, message: "No matching distribution" }; - } + let newUsualBalance = usualBalance; + const callData: Web3FunctionResultCallData[] = []; - if (claimedTokens === BigInt(currentDistribution.value)) { - return { canExec: false, message: "Already claimed latest distribution" }; - } + if (currentDistribution !== undefined) { + const currentDistributionValue = BigInt(currentDistribution.value); - return { - canExec: true, - callData: [ - { - to: execAddress, + if (claimedTokens < currentDistributionValue) { + newUsualBalance += currentDistributionValue - claimedTokens; + + if (pendingDistribution !== undefined) { + callData.push({ + to: distributionAddress, + data: encodeFunctionData({ + abi: DISTRIBUTION_ABI, + functionName: "approveUnchallengedOffChainDistribution", + }), + }); + } + + callData.push({ + to: distributionAddress, data: encodeFunctionData({ abi: DISTRIBUTION_ABI, functionName: "claimOffChainDistribution", args: [ magicUsd0ppAddress, - BigInt(currentDistribution.value), + currentDistributionValue, currentDistribution.merkleProof, ], }), - }, - ], + }); + } + } + + if (newUsualBalance > 0n) { + const quote = await odosQuote({ + endpoint: odosApiEndpoint, + chainId: multiChainProvider.default().network.chainId, + inputTokens: [{ tokenAddress: usualAddress, amount: newUsualBalance }], + outputTokens: [{ tokenAddress: usd0ppAddress, proportion: 1 }], + userAddr: harvesterAddress, + slippageLimitPercent, + disableRFQs: true, + }); + callData.push({ + to: harvesterAddress, + data: encodeFunctionData({ + abi: HARVESTER_ABI, + functionName: "run", + args: [ + quote.transaction.to, + quote.transaction.data, + (quote.outputTokens[0].amount * parseEther("1")) / + parseEther(`${(100 - slippageLimitPercent) / 100}`), + ], + }), + }); + } + + if (callData.length === 0) { + return { canExec: false, message: "No action needed" }; + } + + return { + canExec: true, + callData, }; }, ); diff --git a/web3-functions/magicusd0pp/schema.json b/web3-functions/magicusd0pp/schema.json index 1f24c38..0dfabca 100644 --- a/web3-functions/magicusd0pp/schema.json +++ b/web3-functions/magicusd0pp/schema.json @@ -4,8 +4,13 @@ "memory": 128, "timeout": 30, "userArgs": { - "execAddress": "string", + "distributionAddress": "string", + "harvesterAddress": "string", + "magicUsd0ppAddress": "string", + "usd0ppAddress": "string", + "usualAddress": "string", "usualApiEndpoint": "string", - "magicUsd0ppAddress": "string" + "odosApiEndpoint": "string", + "slippageLimitPercent": "number" } } diff --git a/web3-functions/magicusd0pp/userArgs.json b/web3-functions/magicusd0pp/userArgs.json index 21827cb..bd785b8 100644 --- a/web3-functions/magicusd0pp/userArgs.json +++ b/web3-functions/magicusd0pp/userArgs.json @@ -1,5 +1,10 @@ { - "execAddress": "0x75cC0C0DDD2Ccafe6EC415bE686267588011E36A", - "usualApiEndpoint": "https://app.usual.money/api/rewards", - "magicUsd0ppAddress": "0x73075fD1522893D9dC922991542f98F08F2c1C99" + "distributionAddress": "0x75cC0C0DDD2Ccafe6EC415bE686267588011E36A", + "harvesterAddress": "0x0F9af7168CC8819ce3066867509a7F9170fb108B", + "magicUsd0ppAddress": "0x73075fD1522893D9dC922991542f98F08F2c1C99", + "usd0ppAddress": "0x35D8949372D46B7a3D5A56006AE77B215fc69bC0", + "usualAddress": "0xC4441c2BE5d8fA8126822B9929CA0b81Ea0DE38E", + "usualApiEndpoint": "https://app.usual.money/api", + "odosApiEndpoint": "https://api.odos.xyz", + "slippageLimitPercent": 0.1 } 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 2/8] 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 } From d0e568fbefb69b443a606a340f466b3db666f282 Mon Sep 17 00:00:00 2001 From: 0xmDreamy <0xmDreamy@proton.me> Date: Sun, 29 Dec 2024 13:58:44 +0100 Subject: [PATCH 3/8] update harvester address --- scripts/create-magicusd0pp-task.ts | 2 +- web3-functions/magicusd0pp/userArgs.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/create-magicusd0pp-task.ts b/scripts/create-magicusd0pp-task.ts index 7db6d28..00ebe2d 100644 --- a/scripts/create-magicusd0pp-task.ts +++ b/scripts/create-magicusd0pp-task.ts @@ -29,7 +29,7 @@ const main = async () => { }, web3FunctionArgs: { distributionAddress: "0x75cC0C0DDD2Ccafe6EC415bE686267588011E36A", - harvesterAddress: "0x0F9af7168CC8819ce3066867509a7F9170fb108B", + harvesterAddress: "0x80014629Ca75441599A1efd2283E3f71A8EC0AAB", magicUsd0ppAddress: "0x73075fD1522893D9dC922991542f98F08F2c1C99", usd0ppAddress: "0x35D8949372D46B7a3D5A56006AE77B215fc69bC0", usualAddress: "0xC4441c2BE5d8fA8126822B9929CA0b81Ea0DE38E", diff --git a/web3-functions/magicusd0pp/userArgs.json b/web3-functions/magicusd0pp/userArgs.json index bce1c0d..6f45cb0 100644 --- a/web3-functions/magicusd0pp/userArgs.json +++ b/web3-functions/magicusd0pp/userArgs.json @@ -1,6 +1,6 @@ { "distributionAddress": "0x75cC0C0DDD2Ccafe6EC415bE686267588011E36A", - "harvesterAddress": "0x0F9af7168CC8819ce3066867509a7F9170fb108B", + "harvesterAddress": "0x80014629Ca75441599A1efd2283E3f71A8EC0AAB", "magicUsd0ppAddress": "0x73075fD1522893D9dC922991542f98F08F2c1C99", "usd0ppAddress": "0x35D8949372D46B7a3D5A56006AE77B215fc69bC0", "usualAddress": "0xC4441c2BE5d8fA8126822B9929CA0b81Ea0DE38E", From 016f75f5e7e697766184548e9974263f92d22031 Mon Sep 17 00:00:00 2001 From: 0xmDreamy <0xmDreamy@proton.me> Date: Fri, 3 Jan 2025 22:02:20 +0100 Subject: [PATCH 4/8] use bps instead of percent --- scripts/create-magicusd0pp-task.ts | 2 +- web3-functions/magicusd0pp/index.ts | 8 ++++---- web3-functions/magicusd0pp/schema.json | 2 +- web3-functions/magicusd0pp/userArgs.json | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/create-magicusd0pp-task.ts b/scripts/create-magicusd0pp-task.ts index 00ebe2d..c8fe7ca 100644 --- a/scripts/create-magicusd0pp-task.ts +++ b/scripts/create-magicusd0pp-task.ts @@ -35,7 +35,7 @@ const main = async () => { usualAddress: "0xC4441c2BE5d8fA8126822B9929CA0b81Ea0DE38E", usualApiEndpoint: "https://app.usual.money/api", odosApiEndpoint: "https://api.odos.xyz", - slippageLimitPercent: 0.1, + slippageLimitBps: 10, minimumSwapUsd: 1000, }, }, diff --git a/web3-functions/magicusd0pp/index.ts b/web3-functions/magicusd0pp/index.ts index 985c57e..0a4aca6 100644 --- a/web3-functions/magicusd0pp/index.ts +++ b/web3-functions/magicusd0pp/index.ts @@ -39,7 +39,7 @@ type MagicUsd0ppUserArgs = { usualAddress: Address; usualApiEndpoint: string; odosApiEndpoint: string; - slippageLimitPercent: number; + slippageLimitBps: number; minimumSwapUsd: number; }; @@ -61,7 +61,7 @@ Web3Function.onRun( usualAddress, usualApiEndpoint, odosApiEndpoint, - slippageLimitPercent, + slippageLimitBps, minimumSwapUsd, } = userArgs as MagicUsd0ppUserArgs; @@ -166,7 +166,7 @@ Web3Function.onRun( inputTokens: [{ tokenAddress: usualAddress, amount: newUsualBalance }], outputTokens: [{ tokenAddress: usd0ppAddress, proportion: 1 }], userAddr: harvesterAddress, - slippageLimitPercent, + slippageLimitPercent: slippageLimitBps / 100, disableRFQs: true, }); @@ -186,7 +186,7 @@ Web3Function.onRun( quote.transaction.to, quote.transaction.data, (quote.outputTokens[0].amount * WAD) / - parseEther(`${(100 - slippageLimitPercent) / 100}`), + parseEther(`${(10_000 - slippageLimitBps) / 10_000}`), ], }), }); diff --git a/web3-functions/magicusd0pp/schema.json b/web3-functions/magicusd0pp/schema.json index 32bfaa3..cd4f1f6 100644 --- a/web3-functions/magicusd0pp/schema.json +++ b/web3-functions/magicusd0pp/schema.json @@ -11,7 +11,7 @@ "usualAddress": "string", "usualApiEndpoint": "string", "odosApiEndpoint": "string", - "slippageLimitPercent": "number", + "slippageLimitBps": "number", "minimumSwapUsd": "number" } } diff --git a/web3-functions/magicusd0pp/userArgs.json b/web3-functions/magicusd0pp/userArgs.json index 6f45cb0..9a0191b 100644 --- a/web3-functions/magicusd0pp/userArgs.json +++ b/web3-functions/magicusd0pp/userArgs.json @@ -6,6 +6,6 @@ "usualAddress": "0xC4441c2BE5d8fA8126822B9929CA0b81Ea0DE38E", "usualApiEndpoint": "https://app.usual.money/api", "odosApiEndpoint": "https://api.odos.xyz", - "slippageLimitPercent": 0.1, + "slippageLimitBps": 10, "minimumSwapUsd": 1000 } From 22a04504ae358581bcd44726f447a073259e30f2 Mon Sep 17 00:00:00 2001 From: 0xmDreamy <0xmDreamy@proton.me> Date: Fri, 3 Jan 2025 22:05:04 +0100 Subject: [PATCH 5/8] use block trigger --- scripts/create-magicusd0pp-task.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/create-magicusd0pp-task.ts b/scripts/create-magicusd0pp-task.ts index c8fe7ca..8c5eca8 100644 --- a/scripts/create-magicusd0pp-task.ts +++ b/scripts/create-magicusd0pp-task.ts @@ -4,8 +4,6 @@ import { DEVOPS_SAFE } from "../utils/constants"; const { ethers, w3f } = hre; -const THIRTY_SECONDS = 30 * 1000; - const main = async () => { const magicUsd0pp = w3f.get("magicusd0pp"); @@ -24,8 +22,7 @@ const main = async () => { name: "MagicUSD0pp Handler", web3FunctionHash: cid, trigger: { - type: TriggerType.TIME, - interval: THIRTY_SECONDS, + type: TriggerType.BLOCK, }, web3FunctionArgs: { distributionAddress: "0x75cC0C0DDD2Ccafe6EC415bE686267588011E36A", From a9d214e21b4e0f0378162ec29f1e4dbc762e2c2e Mon Sep 17 00:00:00 2001 From: 0xmDreamy <0xmDreamy@proton.me> Date: Fri, 3 Jan 2025 22:27:45 +0100 Subject: [PATCH 6/8] bump slippage to 15bps --- scripts/create-magicusd0pp-task.ts | 2 +- web3-functions/magicusd0pp/userArgs.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/create-magicusd0pp-task.ts b/scripts/create-magicusd0pp-task.ts index 8c5eca8..9af2f52 100644 --- a/scripts/create-magicusd0pp-task.ts +++ b/scripts/create-magicusd0pp-task.ts @@ -32,7 +32,7 @@ const main = async () => { usualAddress: "0xC4441c2BE5d8fA8126822B9929CA0b81Ea0DE38E", usualApiEndpoint: "https://app.usual.money/api", odosApiEndpoint: "https://api.odos.xyz", - slippageLimitBps: 10, + slippageLimitBps: 15, minimumSwapUsd: 1000, }, }, diff --git a/web3-functions/magicusd0pp/userArgs.json b/web3-functions/magicusd0pp/userArgs.json index 9a0191b..e2da8b5 100644 --- a/web3-functions/magicusd0pp/userArgs.json +++ b/web3-functions/magicusd0pp/userArgs.json @@ -6,6 +6,6 @@ "usualAddress": "0xC4441c2BE5d8fA8126822B9929CA0b81Ea0DE38E", "usualApiEndpoint": "https://app.usual.money/api", "odosApiEndpoint": "https://api.odos.xyz", - "slippageLimitBps": 10, + "slippageLimitBps": 15, "minimumSwapUsd": 1000 } From dbf061e8584665bfb126f0552d560e6a050295c6 Mon Sep 17 00:00:00 2001 From: 0xmDreamy <0xmDreamy@proton.me> Date: Fri, 3 Jan 2025 22:27:54 +0100 Subject: [PATCH 7/8] fix slippage calculation --- web3-functions/magicusd0pp/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/web3-functions/magicusd0pp/index.ts b/web3-functions/magicusd0pp/index.ts index 0a4aca6..5ddc5b8 100644 --- a/web3-functions/magicusd0pp/index.ts +++ b/web3-functions/magicusd0pp/index.ts @@ -185,8 +185,9 @@ Web3Function.onRun( args: [ quote.transaction.to, quote.transaction.data, - (quote.outputTokens[0].amount * WAD) / - parseEther(`${(10_000 - slippageLimitBps) / 10_000}`), + (quote.outputTokens[0].amount * + parseEther(`${(10_000 - slippageLimitBps) / 10_000}`)) / + WAD, ], }), }); From f1ed86269e2c1ee6f5154d1410bff7a51e23c565 Mon Sep 17 00:00:00 2001 From: 0xmDreamy <0xmDreamy@proton.me> Date: Fri, 3 Jan 2025 22:28:50 +0100 Subject: [PATCH 8/8] add deployment --- DEPLOYMENT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index c2aa8a2..817e598 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -20,4 +20,4 @@ | Stargate S\*USDT | [task](https://app.gelato.network/functions/task/0x37ab785e9a1200fb8bac63b431e36da085b177841b24aa0dfab0a4981122da0a:1) | | GM Strategy Harvester | [task](https://app.gelato.network/functions/task/0x40d7aadde626b52e7df27bcab3f92c42faf3f137d50fc98dffc79d20c9119314:42161) | | Reward Distributor | [task](https://app.gelato.network/functions/task/0x1b62e611e8e3d87ec8c7ced57230d341802c0ac6c611afb9a9fb4a3c53dc6ac1:42161) | -| MagicUSD0pp Claimer | [task](https://app.gelato.network/functions/task/0x746fd28a88217d74f693dd3ec738ce699a174b01a875bce3c023262020048d3e:1) | +| MagicUSD0pp Handler | [task](https://app.gelato.network/functions/task/0x0e8f9611aaf09ab1b9920064774a44c4e872a161235b0ea7a03ebfb1188b8fe6:1) |