-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(magicusd0pp): Harvest USUAL rewards
- Loading branch information
Showing
5 changed files
with
246 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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), | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |