-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add 0x swap data #59
Merged
janndriessen
merged 39 commits into
feat/add-swap-quote-provider-protocol
from
feat/add-0x-swap-data
May 24, 2024
Merged
Changes from 24 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
9bb0d52
chore: remove obsolete todo
janndriessen bd07907
build: create zeroex folder
janndriessen 5e3a694
lint
janndriessen 0fdfa35
feat: add zeroe ex swap data
janndriessen aba4e5e
feat: add 0x api
janndriessen f0b46f2
feat: add get swap data to zeroex adapter
janndriessen 9cbc88f
feat: start adding swap quote provider to leveraged quote provider
janndriessen 9f23f28
refactor: get payment token address
janndriessen a3a24ea
feat: add sources and leverage quote provider to fully use swap quote…
janndriessen 772b810
refactor: remove zeroex api from constructor
janndriessen c162745
refactor: leveraged token data util function
janndriessen cecbadc
test: fix import
janndriessen c9e8878
build: fix import
janndriessen d7a034f
feat: add swap quote provider to leveraged extended
janndriessen bf73f64
feat: remove zero ex api dependency
janndriessen cfcd17c
chore: remove unsupported contract type
janndriessen c745320
feat: make swap quote provider a required dependency
janndriessen a91693a
test: remove obsolete test
janndriessen fe8056b
lint
janndriessen f795f87
test: fix test files after removing zeroex api
janndriessen c8513d9
lint
janndriessen 1ecbeef
test: readd arbitrum tests
janndriessen 23f14cc
test: skip eth2xfli tests
janndriessen 095325a
test: fix testing for right output
janndriessen ab06e23
refactor: remove 0x utils
janndriessen 7b3a996
chore: add arbitrum token addresses for util function
janndriessen 5f66112
test: remove obsolete test
janndriessen 12666af
feat: use rpc url for index quote provider
janndriessen cdb0720
refactor: quote folder structure
janndriessen 729869f
refactor: add utils and add tests
janndriessen 71e4ede
feat: add get rpc provider util function
janndriessen bc7002b
feat: make builders use rpc url
janndriessen 28a0b23
feat: use rpc url for all quote providers
janndriessen 7fb8539
test: fix tests adding rpc url
janndriessen c8a88c1
build: fix test script
janndriessen cc042cb
docs: update readme for v3
janndriessen 0e9f5a1
Merge pull request #62 from IndexCoop/feat/add-v3
janndriessen a0ab71a
Merge pull request #61 from IndexCoop/feat/use-rpc-url
janndriessen 1bc68e5
Merge pull request #60 from IndexCoop/feat/remove-0x-utils
janndriessen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -29,19 +29,18 @@ import { | |
LeveragedTransactionBuilder, | ||
ZeroExTransactionBuilder, | ||
} from 'flashmint' | ||
import { ZeroExApi, wei } from 'utils' | ||
import { wei } from 'utils' | ||
|
||
import { LeveragedQuoteProvider } from './leveraged' | ||
import { LeveragedExtendedQuoteProvider } from './leveraged-extended' | ||
import { QuoteProvider } from './quoteProvider' | ||
import { QuoteToken } from './quoteToken' | ||
import { SwapQuoteProvider } from './swap' | ||
import { ZeroExQuoteProvider } from './zeroEx' | ||
import { SwapQuoteProvider } from 'quote/swap' | ||
|
||
export enum FlashMintContractType { | ||
leveraged, | ||
leveragedExtended, | ||
erc4626, | ||
zeroEx, | ||
} | ||
|
||
|
@@ -71,14 +70,13 @@ export class FlashMintQuoteProvider | |
{ | ||
constructor( | ||
private readonly provider: JsonRpcProvider, | ||
private readonly swapQuoteProvider?: SwapQuoteProvider, | ||
private readonly zeroExApiV1?: ZeroExApi | ||
private readonly swapQuoteProvider: SwapQuoteProvider | ||
) {} | ||
|
||
async getQuote( | ||
request: FlashMintQuoteRequest | ||
): Promise<FlashMintQuote | null> { | ||
const { provider, swapQuoteProvider, zeroExApiV1 } = this | ||
const { provider, swapQuoteProvider } = this | ||
const { indexTokenAmount, inputToken, isMinting, outputToken, slippage } = | ||
request | ||
const indexToken = isMinting ? outputToken : inputToken | ||
|
@@ -89,19 +87,11 @@ export class FlashMintQuoteProvider | |
if (contractType === null) { | ||
throw new Error('Index token not supported') | ||
} | ||
if (requiresZeroExV1(contractType)) { | ||
if (!zeroExApiV1) { | ||
throw new Error('Contract type requires ZeroExApiV1 to be defined') | ||
} | ||
} | ||
switch (contractType) { | ||
case FlashMintContractType.leveraged: { | ||
if (!zeroExApiV1) { | ||
throw new Error('Contract type requires ZeroExApiV1 to be defined') | ||
} | ||
const leveragedQuoteProvider = new LeveragedQuoteProvider( | ||
provider, | ||
zeroExApiV1 | ||
swapQuoteProvider | ||
) | ||
const leveragedQuote = await leveragedQuoteProvider.getQuote(request) | ||
if (!leveragedQuote) return null | ||
|
@@ -134,11 +124,8 @@ export class FlashMintQuoteProvider | |
} | ||
} | ||
case FlashMintContractType.leveragedExtended: { | ||
if (!zeroExApiV1) { | ||
throw new Error('Contract type requires ZeroExApiV1 to be defined') | ||
} | ||
const leverageExtendedQuoteProvider = | ||
new LeveragedExtendedQuoteProvider(provider, zeroExApiV1) | ||
new LeveragedExtendedQuoteProvider(provider, swapQuoteProvider) | ||
const leveragedExtendedQuote = | ||
await leverageExtendedQuoteProvider.getQuote(request) | ||
if (!leveragedExtendedQuote) return null | ||
|
@@ -175,11 +162,6 @@ export class FlashMintQuoteProvider | |
} | ||
} | ||
case FlashMintContractType.zeroEx: { | ||
if (!swapQuoteProvider) { | ||
throw new Error( | ||
'Contract type requires SwapQuoteProvider to be defined' | ||
) | ||
} | ||
const zeroExQuoteProvider = new ZeroExQuoteProvider( | ||
provider, | ||
swapQuoteProvider | ||
|
@@ -255,9 +237,3 @@ function getContractType( | |
return FlashMintContractType.leveraged | ||
return null | ||
} | ||
|
||
function requiresZeroExV1(contractType: FlashMintContractType): boolean { | ||
if (contractType === FlashMintContractType.leveraged) return true | ||
if (contractType === FlashMintContractType.leveragedExtended) return true | ||
return false | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. obsolete as the swap quote provider is always required |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swapQuoteProvider
as required dependencyzeroExApiV1
as dependency