-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@nftx/trade): add fulfill function
this function takes any quote from fetchQuote and fulfills it, regardless of whether it's a sell/buy, a mint/redeem, or an ERC20 quote
- Loading branch information
1 parent
6d71440
commit 7ec4899
Showing
9 changed files
with
75 additions
and
21 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
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
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,40 @@ | ||
import { MarketplaceQuote, Provider, Signer } from '@nftx/types'; | ||
import tradeErc20 from './tradeErc20'; | ||
import swap from './swap'; | ||
import redeem from './redeem'; | ||
import mint from './mint'; | ||
import sell from './sell'; | ||
import buy from './buy'; | ||
import { UnknownError } from '@nftx/errors'; | ||
|
||
/** Fulfills any quote returned by @nftx/api's fetchQuote method */ | ||
const fulfill = ({ | ||
network, | ||
quote, | ||
signer, | ||
provider, | ||
}: { | ||
quote: Pick<MarketplaceQuote, 'type' | 'methodParameters'>; | ||
network: number; | ||
signer: Signer; | ||
provider: Provider; | ||
}) => { | ||
switch (quote.type) { | ||
case 'buy': | ||
return buy({ provider, quote, signer, network }); | ||
case 'sell': | ||
return sell({ provider, quote, signer, network }); | ||
case 'mint': | ||
return mint({ provider, quote, signer }); | ||
case 'redeem': | ||
return redeem({ quote, provider, signer }); | ||
case 'swap': | ||
return swap({ quote, provider, signer, network }); | ||
case 'erc20': | ||
return tradeErc20({ provider, quote, signer, network }); | ||
default: | ||
throw new UnknownError(`Unknown quote type: ${quote.type}`); | ||
} | ||
}; | ||
|
||
export default fulfill; |
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