Skip to content

Commit

Permalink
Merge pull request #130 from reservoirprotocol/element
Browse files Browse the repository at this point in the history
Element
  • Loading branch information
georgeroman authored May 15, 2024
2 parents 7063f39 + 94ccaf5 commit 0a41412
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
41 changes: 41 additions & 0 deletions src/tests/element/element.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,45 @@ describe("Element", () => {
}
}
});

test("parseNewOrder", async () => {
const parsed = await element.parseOrder({
chain: "eth",
chainId: "0x1",
orderHash:
"0x3faecdffbbe4de382e8087fddec9a3227615baa1618fd51293f7503e4a651766_1",
orderId: "1442690384920285728",
expirationTime: 1718118712,
listingTime: 1715526658,
createTime: 1715526723,
maker: "0xdb2ab5671bf17ca408fe75e90571fbe675d01c00",
taker: "0x0000000000000000000000000000000000000000",
side: 1,
saleKind: 3,
paymentToken: "0x0000000000000000000000000000000000000000",
quantity: "1",
priceBase: 0.0025,
priceUSD: 7.319725,
price: 0.0025,
standard: "element-ex-v3",
contractAddress: "0x0a252663dbcc0b073063d6420a40319e438cfa59",
tokenId: "62708",
schema: "ERC721",
extra: null,
exchangeData:
'{"basicCollections":[{"nftAddress":"0x0a252663dbcc0b073063d6420a40319e438cfa59","platformFee":50,"royaltyFeeRecipient":"0x0000000000000000000000000000000000000000","royaltyFee":0,"items":[{"erc20TokenAmount":"2500000000000000","nftId":"62708"}]}],"collections":null,"startNonce":1,"nonce":1,"hashNonce":"0","platformFeeRecipient":"0x00ca62445b06a9adc1879a44485b4efdcb7b75f3","v":0,"r":"","s":"","listingTime":1715526658,"expirationTime":1718118712,"maker":"0xdb2ab5671bf17ca408fe75e90571fbe675d01c00","hash":"0x3faecdffbbe4de382e8087fddec9a3227615baa1618fd51293f7503e4a651766","paymentToken":"0x0000000000000000000000000000000000000000","signatureType":0,"oracleSignature":1,"extraData":""}',
} as any);

// console.log(
// "parsed",
// JSON.stringify({
// orders: [
// {
// kind: "element",
// data: parsed?.params,
// },
// ],
// })
// );
});
});
16 changes: 13 additions & 3 deletions src/utils/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export type ElementOrder = {
listingTime: number;

orderHash: string;
elementId: string;

maker: string;
taker: string;

Expand Down Expand Up @@ -120,8 +122,10 @@ export class Element {
}

const json = JSON.parse(params.exchangeData);

let order: Sdk.Element.Order;
if (params.saleKind === SaleKind.BatchSignedOrder) {
return new Sdk.Element.Order(config.chainId, {
order = new Sdk.Element.Order(config.chainId, {
...json,
erc20Token: json.paymentToken,
});
Expand All @@ -130,7 +134,7 @@ export class Element {
params.schema.toLowerCase() === "erc721"
? json.order.nftProperties
: json.order.erc1155TokenProperties;
return new Sdk.Element.Order(config.chainId, {
order = new Sdk.Element.Order(config.chainId, {
direction:
params.side === 1
? Sdk.Element.Types.TradeDirection.SELL
Expand All @@ -146,8 +150,14 @@ export class Element {
: String(params.quantity),
});
}

if (json.oracleSignature) {
(order.params as any).elementId = params.elementId;
}

return order;
} catch {
// Skip any errors
// Skip errors
}
}
}

0 comments on commit 0a41412

Please sign in to comment.