Skip to content

Commit

Permalink
feat: add rarible-v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ryosevenf committed Oct 30, 2023
1 parent 1da5527 commit a630c13
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * as blurTypes from "./blur";
export * as looksrareTypes from "./looksrare";
export * as seaportTypes from "./seaport";
export * as raribleV2Types from "./rarible-v2";
export * as visualizer from "./visualizer";

export enum ASSET_TYPE {
Expand Down
25 changes: 25 additions & 0 deletions src/types/rarible-v2.ts
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;
};
1 change: 1 addition & 0 deletions src/visualizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export enum PROTOCOL_ID {
LOOKSRARE_EXCHANGE = "LOOKSRARE_EXCHANGE",
LOOKSRARE_EXCHANGE_V2 = "LOOKSRARE_EXCHANGE_V2",
BLUR_IO_MARKETPLACE = "BLUR_IO_MARKETPLACE",
RARIBLE_EXCHANGE_V2 = "RARIBLE_EXCHANGE_V2",
ERC20_PERMIT = "ERC20_PERMIT",
}

Expand Down
68 changes: 68 additions & 0 deletions src/visualizer/rarible-v2/index.ts
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;

0 comments on commit a630c13

Please sign in to comment.