-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 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,25 @@ | ||
/** | ||
* @see https://github.com/rarible/sdk/blob/a04dd75832a7110a91371afc8721b034d5b35dea/packages/ethereum/sdk/src/order/eip712.ts | ||
*/ | ||
|
||
export type RaribleV2AssetType = { | ||
assetClass: string; | ||
data: string; | ||
}; | ||
|
||
export type RaribleV2Asset = { | ||
assetType: RaribleV2AssetType; | ||
value: number; | ||
}; | ||
|
||
export type RaribleV2Order = { | ||
maker: string; | ||
makeAsset: RaribleV2Asset; | ||
taker: string; | ||
takeAsset: RaribleV2Asset; | ||
salt: number; | ||
start: number; | ||
end: number; | ||
dataType: string; | ||
data: string; | ||
}; |
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,68 @@ | ||
import { Domain, EIP712Protocol, VisualizationResult } from "../../types/visualizer"; | ||
import { RaribleV2Order } from "../../types/rarible-v2"; | ||
import { PROTOCOL_ID } from ".."; | ||
import { ASSET_TYPE, AssetInOut } from "../../types"; | ||
import { ZERO_ADDRESS, getPaymentAssetType } from "../../utils"; | ||
|
||
const { NATIVE } = ASSET_TYPE; | ||
|
||
export const RARIBLE_VERIFYING_CONTRACTS = { | ||
1: "0x9757F2d2b135150BBeb65308D4a91804107cd8D6", //Ethereum | ||
137: "0x12b3897a36fDB436ddE2788C06Eff0ffD997066e", //Polygon | ||
}; | ||
|
||
export const RARIBLE_SUPPORTED_CHAINS = Object.keys(RARIBLE_VERIFYING_CONTRACTS).map( | ||
Number | ||
); | ||
|
||
export const isCorrectDomain = (domain: Domain) => { | ||
const verifyingContracts = RARIBLE_VERIFYING_CONTRACTS as Record<string, string>; | ||
return ( | ||
RARIBLE_SUPPORTED_CHAINS.includes(Number(domain.chainId)) && | ||
verifyingContracts[domain.chainId] !== undefined && | ||
verifyingContracts[domain.chainId].toLocaleLowerCase() === | ||
domain.verifyingContract.toLocaleLowerCase() | ||
); | ||
}; | ||
|
||
export const visualize = ( | ||
message: RaribleV2Order, | ||
domain: Domain | ||
): VisualizationResult => { | ||
if (!isCorrectDomain(domain)) throw new Error("wrong rarible-v2 domain"); | ||
|
||
// TODO | ||
const assetsIn: AssetInOut[] = [ | ||
// { | ||
// address: makerAssetType === NATIVE ? ZERO_ADDRESS : message.makerAsset, | ||
// type: makerAssetType, | ||
// amounts: [message.makingAmount], | ||
// }, | ||
]; | ||
|
||
// TODO | ||
const assetsOut: AssetInOut[] = [ | ||
// { | ||
// address: takerAssetType === NATIVE ? ZERO_ADDRESS : message.takerAsset, | ||
// type: takerAssetType, | ||
// amounts: [message.takingAmount], | ||
// }, | ||
]; | ||
|
||
return { | ||
protocol: PROTOCOL_ID.RARIBLE_EXCHANGE_V2, | ||
assetsIn, | ||
assetsOut, | ||
liveness: { | ||
from: message.start * 1000, | ||
to: message.end * 1000, | ||
}, | ||
approvals: [], | ||
}; | ||
}; | ||
|
||
const raribleV2: EIP712Protocol<RaribleV2Order> = { | ||
isCorrectDomain, | ||
visualize, | ||
}; | ||
export default raribleV2; |