Skip to content

Commit

Permalink
fix: 1inch fusion type
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielantonyxaviour committed Oct 31, 2023
1 parent 336ea73 commit a9577db
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/types/oneinch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BytesLike } from "ethers";
* @see https://portal.1inch.dev/documentation/fusion/fusion-sdk/for-resolvers/auction-calculator
*/

export type OneInchFusionOrderV3 = {
export type OneInchFusionOrder = {
// Contains of auction start time, auction duration, initial rate bump, fee and some unique value
salt: string;
// Address of the asset user want to sell
Expand Down
10 changes: 5 additions & 5 deletions src/visualizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SeaPortPayload } from "../types/seaport";
import { BlurIoOrder } from "../types/blur";
import { LooksrareMakerOrderWithEncodedParams } from "../types/looksrare";
import { LooksRareV2MakerOrder } from "../types/looksrare-v2";
import { OneInchFusionOrderV3 } from "../types/oneinch";
import { OneInchFusionOrder } from "../types/oneinch";
import { RaribleOrder } from "../types/rarible";

import blurIo from "./blur-io";
Expand All @@ -24,15 +24,15 @@ export enum PROTOCOL_ID {
BLUR_IO_MARKETPLACE = "BLUR_IO_MARKETPLACE",
ERC20_PERMIT = "ERC20_PERMIT",
RARIBLE = "EXCHANGE",
ONE_INCH_FUSION = "ONE_INCH_FUSION",
ONEINCH_FUSION = "ONEINCH_FUSION",
}

export const getProtocolId = (domain: Domain): PROTOCOL_ID | undefined => {
if (seaport.isCorrectDomain(domain)) return PROTOCOL_ID.OPENSEA_SEAPORT;
if (blurIo.isCorrectDomain(domain)) return PROTOCOL_ID.BLUR_IO_MARKETPLACE;
if (looksrareV2.isCorrectDomain(domain)) return PROTOCOL_ID.LOOKSRARE_EXCHANGE_V2;
if (looksrare.isCorrectDomain(domain)) return PROTOCOL_ID.LOOKSRARE_EXCHANGE;
if (oneinch.isCorrectDomain(domain)) return PROTOCOL_ID.ONE_INCH_FUSION;
if (oneinch.isCorrectDomain(domain)) return PROTOCOL_ID.ONEINCH_FUSION;
if (rarible.isCorrectDomain(domain)) return PROTOCOL_ID.RARIBLE;
return;
};
Expand Down Expand Up @@ -62,8 +62,8 @@ export default async function visualize<T extends object>(
case PROTOCOL_ID.BLUR_IO_MARKETPLACE:
return blurIo.visualize(message as BlurIoOrder, domain);

case PROTOCOL_ID.ONE_INCH_FUSION:
return oneinch.visualize(message as OneInchFusionOrderV3, domain);
case PROTOCOL_ID.ONEINCH_FUSION:
return oneinch.visualize(message as OneInchFusionOrder, domain);

case PROTOCOL_ID.RARIBLE:
return rarible.visualize(message as RaribleOrder, domain);
Expand Down
17 changes: 5 additions & 12 deletions src/visualizer/oneinch/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PROTOCOL_ID } from "..";
import { ASSET_TYPE, AssetInOut } from "../../types";
import { OneInchFusionOrderV3 } from "../../types/oneinch";
import { OneInchFusionOrder } from "../../types/oneinch";
import { Domain, EIP712Protocol, VisualizationResult } from "../../types/visualizer";
import { WizardError, ZERO_ADDRESS, getPaymentAssetType } from "../../utils";
import { getAuctionEndTime, getAuctionStartTime } from "./utils";
Expand All @@ -19,15 +19,15 @@ export const isCorrectDomain = (domain: Domain) => {
* @returns Returns the visualization result in the ERC6865 format
*/
export const visualize = (
message: OneInchFusionOrderV3,
message: OneInchFusionOrder,
domain: Domain
): VisualizationResult => {
/** Verifies the domain of the oneinch limit order */
if (!isCorrectDomain(domain)) throw new Error("wrong oneinch domain");

/** Returns the ERC6865 format of the order */
return {
protocol: PROTOCOL_ID.ONE_INCH_FUSION,
protocol: PROTOCOL_ID.ONEINCH_FUSION,
assetsIn: [
{
address: message.takerAsset,
Expand Down Expand Up @@ -67,17 +67,10 @@ const supportedChains = [
* @see https://github.com/1inch/fusion-sdk/blob/main/src/constants.ts
*/
const addressesBook = [
"0xa88800cd213da5ae406ce248380802bd53b47647", // Ethereum Mainnet LimitOrderProtocol
"0x1d0ae300eec4093cee4367c00b228d10a5c7ac63", // Binance Smart Chain LimitOrderProtocol
"0x1e8ae092651e7b14e4d0f93611267c5be19b8b9f", // Polygon LimitOrderProtocol
"0x4bc3e539aaa5b18a82f6cd88dc9ab0e113c63377", // Arbitrum LimitOrderProtocol
"0x7731f8df999a9441ae10519617c24568dc82f697", // Avalanche LimitOrderProtocol
"0xd89adc20c400b6c45086a7f6ab2dca19745b89c2", // Optimism LimitOrderProtocol
"0xa218543cc21ee9388fa1e509f950fd127ca82155", // Fantom LimitOrderProtocol
"0xcbdb7490968d4dbf183c60fc899c2e9fbd445308", // Gnosis LimitOrderProtocol
"0x1111111254eeb25477b68fb85ed929f73a960582", // Consistent address for all chains
].map((e) => e.toLocaleLowerCase());

const oneinch: EIP712Protocol<OneInchFusionOrderV3> = {
const oneinch: EIP712Protocol<OneInchFusionOrder> = {
isCorrectDomain,
visualize,
};
Expand Down
4 changes: 2 additions & 2 deletions test/visualizer/oneinch/data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OneInchFusionOrderV3 } from "../../../src/types/oneinch";
import { OneInchFusionOrder } from "../../../src/types/oneinch";

const oneinchNormalLimitOrder: OneInchFusionOrderV3 = {
const oneinchNormalLimitOrder: OneInchFusionOrder = {
salt: "45118768841948961586167738353692277076075522015101619148498725069326976558864",
makerAsset: "0x5f04D47D698F79d76F85E835930170Ff4c4EBdB7",
takerAsset: "0x000075B45Dff84C00Cf597d5C3E766108CeA0000",
Expand Down
12 changes: 6 additions & 6 deletions test/visualizer/oneinch/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { OneInchFusionOrderV3 } from "../../../src/types/oneinch";
import { OneInchFusionOrder } from "../../../src/types/oneinch";
import { Domain } from "../../../src/types/visualizer";
import visualize from "../../../src/visualizer";
import oneinch from "../../../src/visualizer/oneinch";
import { oneinchNormalLimitOrder } from "./data";

describe("oneinch", () => {
const oneinchDomain: Domain = {
verifyingContract: "0x119c71D3BbAC22029622cbaEc24854d3D32D2828",
name: "1inch Limit Order Protocol",
version: "2",
verifyingContract: "0x1111111254eeb25477b68fb85ed929f73a960582",
name: "1inch Aggregation Router",
version: "5",
chainId: "1",
};

Expand All @@ -28,13 +28,13 @@ describe("oneinch", () => {
});

it("should successfully visualize oneinch limit order", async () => {
const result = await visualize<OneInchFusionOrderV3>(
const result = await visualize<OneInchFusionOrder>(
oneinchNormalLimitOrder,
oneinchDomain
);

expect(result).toEqual({
protocol: "ONE_INCH_FUSION",
protocol: "ONEINCH_FUSION",
assetsIn: [
{
address: "0x000075B45Dff84C00Cf597d5C3E766108CeA0000",
Expand Down

0 comments on commit a9577db

Please sign in to comment.