diff --git a/.changeset/shiny-cows-sing.md b/.changeset/shiny-cows-sing.md new file mode 100644 index 000000000..a2b584005 --- /dev/null +++ b/.changeset/shiny-cows-sing.md @@ -0,0 +1,5 @@ +--- +"@ark-project/core": patch +--- + +use offer currency address optional param diff --git a/packages/core/src/actions/order/createAuction.ts b/packages/core/src/actions/order/createAuction.ts index 2df9e1931..163f32f8f 100644 --- a/packages/core/src/actions/order/createAuction.ts +++ b/packages/core/src/actions/order/createAuction.ts @@ -65,7 +65,8 @@ const createAuction = async ( const order: OrderV1 = { route: RouteType.Erc721ToErc20, - currencyAddress: config.starknetCurrencyContract, + currencyAddress: + baseOrder.currencyAddress ?? config.starknetCurrencyContract, currencyChainId: chainId, salt: 1, offerer: starknetAccount.address, diff --git a/packages/core/src/actions/order/createListing.ts b/packages/core/src/actions/order/createListing.ts index 993f51256..76bf43461 100644 --- a/packages/core/src/actions/order/createListing.ts +++ b/packages/core/src/actions/order/createListing.ts @@ -49,7 +49,8 @@ const createListing = async ( const order: OrderV1 = { route: RouteType.Erc721ToErc20, - currencyAddress: config.starknetCurrencyContract, + currencyAddress: + baseOrder.currencyAddress ?? config.starknetCurrencyContract, currencyChainId: chainId, salt: 1, offerer: starknetAccount.address, diff --git a/packages/core/src/actions/order/createOffer.ts b/packages/core/src/actions/order/createOffer.ts index a2a34132c..b5e248499 100644 --- a/packages/core/src/actions/order/createOffer.ts +++ b/packages/core/src/actions/order/createOffer.ts @@ -46,6 +46,13 @@ const createOffer = async ( currentDate.setDate(currentDate.getDate() + 30); const startDate = baseOrder.startDate || Math.floor(Date.now() / 1000); const endDate = baseOrder.endDate || Math.floor(currentDate.getTime() / 1000); + const currencyAddress = + baseOrder.currencyAddress || config.starknetCurrencyContract; + + if (currencyAddress !== approveInfo.currencyAddress) { + throw new Error("Invalid currency address, offer and approveInfo mismatch"); + } + const chainId = await config.starknetProvider.getChainId(); const currentAllowance = await getAllowance( config, @@ -55,7 +62,8 @@ const createOffer = async ( const allowance = currentAllowance + approveInfo.amount; const order: OrderV1 = { route: RouteType.Erc20ToErc721, - currencyAddress: config.starknetCurrencyContract, + currencyAddress: + baseOrder.currencyAddress ?? config.starknetCurrencyContract, currencyChainId: chainId, salt: 1, offerer: starknetAccount.address, diff --git a/packages/core/tests/createAuction.test.ts b/packages/core/tests/createAuction.test.ts index 1783c6efe..71ef4f0d6 100644 --- a/packages/core/tests/createAuction.test.ts +++ b/packages/core/tests/createAuction.test.ts @@ -33,6 +33,33 @@ describe("createAuction", () => { expect(orderType).toEqual("AUCTION"); }, 50_000); + it("default: with custom currency", async () => { + const { seller, listingBroker } = accounts; + const tokenId = await mintERC721({ account: seller }); + + const orderHash = await createAuction(config, { + starknetAccount: seller, + order: { + brokerId: listingBroker.address, + tokenAddress: STARKNET_NFT_ADDRESS, + tokenId, + startAmount: BigInt(1), + endAmount: BigInt(10), + currencyAddress: + "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d" + }, + approveInfo: { + tokenAddress: STARKNET_NFT_ADDRESS, + tokenId + } + }); + + const orderTypeCairo = await getOrderType(config, { orderHash }); + const orderType = getTypeFromCairoCustomEnum(orderTypeCairo.orderType); + + expect(orderType).toEqual("AUCTION"); + }, 50_000); + it("error: invalid start date", async () => { const { seller, listingBroker } = accounts; const tokenId = await mintERC721({ account: seller }); diff --git a/packages/core/tests/createListing.test.ts b/packages/core/tests/createListing.test.ts index 7918a8587..ae34819dd 100644 --- a/packages/core/tests/createListing.test.ts +++ b/packages/core/tests/createListing.test.ts @@ -29,4 +29,28 @@ describe("createListing", () => { expect(orderStatus).toBe("Open"); }, 50_000); + + it("default: with custom currency", async () => { + const { seller } = accounts; + const tokenId = await mintERC721({ account: seller }); + + const orderHash = await createListing(config, { + starknetAccount: seller, + order: { + brokerId: accounts.listingBroker.address, + tokenAddress: STARKNET_NFT_ADDRESS, + tokenId, + startAmount: BigInt(1), + currencyAddress: + "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d" + }, + approveInfo: { + tokenAddress: STARKNET_NFT_ADDRESS, + tokenId + } + }); + const { orderStatus } = await getOrderStatus(config, { orderHash }); + + expect(orderStatus).toBe("Open"); + }, 50_000); }); diff --git a/packages/core/tests/createOffer.test.ts b/packages/core/tests/createOffer.test.ts index ea2cbf415..2de1df00e 100644 --- a/packages/core/tests/createOffer.test.ts +++ b/packages/core/tests/createOffer.test.ts @@ -11,10 +11,10 @@ describe("createOffer", () => { it("default", async () => { const { seller, buyer } = accounts; const tokenId = await mintERC721({ account: seller }); - await mintERC20({ account: buyer, amount: 1 }); + await mintERC20({ account: buyer, amount: 1000 }); const orderHash = await createOffer(config, { - starknetAccount: seller, + starknetAccount: buyer, offer: { brokerId: accounts.listingBroker.address, tokenAddress: STARKNET_NFT_ADDRESS, @@ -35,4 +35,59 @@ describe("createOffer", () => { expect(orderStatusAfter).toBe("Open"); }, 50_000); + + // it("default: custom currency", async () => { + // const { seller, buyer } = accounts; + // const tokenId = await mintERC721({ account: seller }); + // await mintERC20({ account: buyer, amount: 1000 }); + + // const orderHash = await createOffer(config, { + // starknetAccount: buyer, + // offer: { + // brokerId: accounts.listingBroker.address, + // tokenAddress: STARKNET_NFT_ADDRESS, + // tokenId, + // startAmount: BigInt(10), + // currencyAddress: + // "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7" + // }, + // approveInfo: { + // currencyAddress: + // "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", + // amount: BigInt(10) + // } + // }); + + // await new Promise((resolve) => setTimeout(resolve, 5_000)); + + // const { orderStatus: orderStatusAfter } = await getOrderStatus(config, { + // orderHash + // }); + + // expect(orderStatusAfter).toBe("Open"); + // }, 50_000); + + it("error: invalid currency address", async () => { + const { seller, buyer } = accounts; + const tokenId = await mintERC721({ account: seller }); + await mintERC20({ account: buyer, amount: 1 }); + + await expect( + createOffer(config, { + starknetAccount: buyer, + offer: { + brokerId: accounts.listingBroker.address, + tokenAddress: STARKNET_NFT_ADDRESS, + tokenId, + startAmount: BigInt(10), + currencyAddress: + "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d" + }, + approveInfo: { + currencyAddress: config.starknetCurrencyContract, + amount: BigInt(10) + } + }) + ).rejects.toThrow(); + }, 50_000); });