Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(PLTF-215): fixes transactions for backend service #594

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions packages/ethereum/sdk/src/order/fill-order/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,20 @@ export class OrderFiller {
public acceptBid: SellOrderAction = this.getFillAction<SellOrderRequest>()

async getBuyTx({ request, from }: GetOrderBuyTxRequest): Promise<TransactionData> {
if (!this.isNonInvertableOrder(request.order) && !from) {
throw new Error("'From' field must be specified for this order type")
}
const inverted = this.isNonInvertableOrder(request.order) ? request.order : await this.invertOrder(request, from)
if (request.assetType && inverted.make.assetType.assetClass === "COLLECTION") {
inverted.make.assetType = await this.checkAssetType(request.assetType)
}
const { functionCall, options } = await this.getTransactionRequestData(request, inverted)
const { functionCall, options } = await this.getTransactionRequestData(
request,
inverted,
{
disableCheckingBalances: true,
}
)
const callInfo = await functionCall.getCallInfo()
const value = options.value?.toString() || "0"
return {
Expand Down Expand Up @@ -237,7 +246,9 @@ export class OrderFiller {
}

private async getTransactionRequestData(
request: FillOrderRequest, inverted: SimpleOrder
request: FillOrderRequest,
inverted: SimpleOrder,
options?: { disableCheckingBalances?: boolean }
): Promise<OrderFillSendData> {
switch (request.order.type) {
case "RARIBLE_V1":
Expand All @@ -258,7 +269,10 @@ export class OrderFiller {
<OpenSeaV1OrderFillRequest>request
)
case "SEAPORT_V1":
return this.seaportHandler.getTransactionData(<SeaportV1OrderFillRequest>request)
return this.seaportHandler.getTransactionData(
<SeaportV1OrderFillRequest>request,
{ disableCheckingBalances: options?.disableCheckingBalances }
)
case "LOOKSRARE":
return this.looksrareHandler.getTransactionData(<LooksrareOrderFillRequest>request)
case "LOOKSRARE_V2":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,14 @@ export const validateBasicFulfillBalancesAndApprovals = ({
timeBasedItemParams,
offererOperator,
fulfillerOperator,
disableCheckingBalances,
}: {
offererBalancesAndApprovals: BalancesAndApprovals;
fulfillerBalancesAndApprovals: BalancesAndApprovals;
timeBasedItemParams: TimeBasedItemParams;
offererOperator: string;
fulfillerOperator: string;
disableCheckingBalances?: boolean;
} & Pick<OrderParameters, "offer" | "consideration">) => {
validateOfferBalancesAndApprovals({
offer,
Expand Down Expand Up @@ -253,7 +255,7 @@ export const validateBasicFulfillBalancesAndApprovals = ({
operator: fulfillerOperator,
})

if (insufficientBalances.length > 0) {
if (!disableCheckingBalances && insufficientBalances.length > 0) {
throw new Error(
"The fulfiller does not have the balances needed to fulfill."
)
Expand All @@ -272,6 +274,7 @@ export const validateStandardFulfillBalancesAndApprovals = ({
timeBasedItemParams,
offererOperator,
fulfillerOperator,
disableCheckingBalances,
}: Pick<OrderParameters, "offer" | "consideration"> & {
offerCriteria: InputCriteria[];
considerationCriteria: InputCriteria[];
Expand All @@ -280,6 +283,7 @@ export const validateStandardFulfillBalancesAndApprovals = ({
timeBasedItemParams: TimeBasedItemParams;
offererOperator: string;
fulfillerOperator: string;
disableCheckingBalances?: boolean;
}) => {
validateOfferBalancesAndApprovals({
offer,
Expand Down Expand Up @@ -313,7 +317,7 @@ export const validateStandardFulfillBalancesAndApprovals = ({
operator: fulfillerOperator,
})

if (insufficientBalances.length > 0) {
if (!disableCheckingBalances && insufficientBalances.length > 0) {
throw new Error(
"The fulfiller does not have the balances needed to fulfill."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export async function getFulfillAdvancedOrderWrapperData({
conduitKey,
recipientAddress,
seaportContract,
disableCheckingBalances,
}: {
order: Order;
unitsToFill?: BigNumberValue;
Expand All @@ -46,6 +47,7 @@ export async function getFulfillAdvancedOrderWrapperData({
recipientAddress: string;
timeBasedItemParams: TimeBasedItemParams;
seaportContract: EthereumContract,
disableCheckingBalances?: boolean;
}) {
// If we are supplying units to fill, we adjust the order by the minimum of the amount to fill and
// the remaining order left to be fulfilled
Expand Down Expand Up @@ -105,6 +107,7 @@ export async function getFulfillAdvancedOrderWrapperData({
timeBasedItemParams,
offererOperator,
fulfillerOperator,
disableCheckingBalances,
})

const orderAccountingForTips: OrderStruct = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export async function fulfillOrder(
ethereum: Ethereum,
send: SendFunction,
simpleOrder: SimpleSeaportV1Order,
{ tips, unitsToFill }: {tips?: TipInputItem[], unitsToFill?: BigNumberValue}
{ tips, unitsToFill, disableCheckingBalances }: {
tips?: TipInputItem[],
unitsToFill?: BigNumberValue,
disableCheckingBalances?: boolean
}
) {
const seaportContract = createSeaportV14Contract(ethereum, toAddress(simpleOrder.data.protocol))
const order = convertAPIOrderToSeaport(simpleOrder)
Expand Down Expand Up @@ -134,6 +138,7 @@ export async function fulfillOrder(
timeBasedItemParams,
offererOperator,
fulfillerOperator,
disableCheckingBalances,
})
return getfulfillBasicOrderData({
order: sanitizedOrder,
Expand Down Expand Up @@ -191,6 +196,7 @@ export async function approveBeforeBasicFulfillOrder(
timeBasedItemParams,
offererOperator,
fulfillerOperator,
disableCheckingBalances,
}: {
ethereum: Ethereum,
send: SendFunction,
Expand All @@ -201,6 +207,7 @@ export async function approveBeforeBasicFulfillOrder(
timeBasedItemParams: TimeBasedItemParams;
offererOperator: string;
fulfillerOperator: string;
disableCheckingBalances?: boolean;
}) {
const { offer, consideration } = order.parameters

Expand All @@ -214,6 +221,7 @@ export async function approveBeforeBasicFulfillOrder(
timeBasedItemParams,
offererOperator,
fulfillerOperator,
disableCheckingBalances,
})

const approvalActions = await getApprovalActions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ export async function prepareSeaportExchangeData(
unitsToFill,
encodedFeesValue,
totalFeeBasisPoints,
disableCheckingBalances,
}: {
unitsToFill?: BigNumberValue
// converted to single uint fee value, values should be in right order in case of use for batch purchase
encodedFeesValue: BigNumber,
totalFeeBasisPoints: number,
disableCheckingBalances?: boolean;
}
): Promise<PreparedOrderRequestDataForExchangeWrapper> {
const seaportContract = getSeaportContract(ethereum, toAddress(simpleOrder.data.protocol))
Expand Down Expand Up @@ -122,6 +124,7 @@ export async function prepareSeaportExchangeData(
conduitKey,
recipientAddress,
seaportContract,
disableCheckingBalances,
})

const valueForSending = calcValueWithFees(toBigNumber(fulfillOrdersData.value), totalFeeBasisPoints)
Expand Down
8 changes: 4 additions & 4 deletions packages/ethereum/sdk/src/order/fill-order/seaport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,14 @@ export class SeaportOrderHandler {
}
async getTransactionData(
request: SeaportV1OrderFillRequest,
requestOptions?: { disableCheckingBalances?: boolean },
): Promise<OrderFillSendData> {
const ethereum = getRequiredWallet(this.ethereum)
const { order } = request
if (order.start === undefined || order.end === undefined) {
throw new Error("Order should includes start/end fields")
}

if (request.order.taker) {
throw new Error("You can't fill private orders")
}

const { unitsToFill, takeIsNft } = getUnitsToFill(request)

let tips: TipInputItem[] | undefined = []
Expand Down Expand Up @@ -128,6 +125,7 @@ export class SeaportOrderHandler {
{
unitsToFill,
tips,
disableCheckingBalances: requestOptions?.disableCheckingBalances,
},
)

Expand Down Expand Up @@ -157,6 +155,7 @@ export class SeaportOrderHandler {
request: SeaportV1OrderFillRequest,
originFees: Part[] | undefined,
feeValue: BigNumber,
options?: { disableCheckingBalances?: boolean },
): Promise<PreparedOrderRequestDataForExchangeWrapper> {
if (!this.ethereum) {
throw new Error("Wallet undefined")
Expand Down Expand Up @@ -194,6 +193,7 @@ export class SeaportOrderHandler {
unitsToFill: unitsToFill,
encodedFeesValue: feeValueWithCurrency,
totalFeeBasisPoints: totalFeeBasisPoints,
disableCheckingBalances: options?.disableCheckingBalances,
},
)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/transaction-backend/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ process.env.ETEHREUM_RPC_URL="https://dev-ethereum-node.rarible.com"

process.env.MANTLE_SDK_ENV="dev-mantle"
process.env.MANTLE_API_URL="https://dev-mantle-api.rarible.org"
process.env.MANTLE_RPC_URL="https://dev-mantle-node.rarible.com"
process.env.MANTLE_RPC_URL="https://dev-mantle-node.rarible.com"
7 changes: 4 additions & 3 deletions packages/transaction-backend/src/orders/fill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe.skip("get buy transaction", () => {
takeAssetType: {
assetClass: "ETH",
},
priceDecimal: "0.000000000000000002",
priceDecimal: "0.0002",
payouts: [],
originFees: [],
end: Date.now() + 1000 * 60 * 60 * 24 * 30,
Expand Down Expand Up @@ -85,7 +85,7 @@ describe.skip("get buy transaction", () => {
}
await web3Buyer.eth.sendSignedTransaction(signedBuyerTx.rawTransaction)

await retry(5, 2000, async () => {
await retry(10, 3000, async () => {
await sdkItemOwner.apis.nftOwnership.getNftOwnershipById({
ownershipId: `${mintResult.itemId}:${buyerAddress}`,
})
Expand Down Expand Up @@ -123,7 +123,7 @@ describe.skip("get buy transaction", () => {
takeAssetType: {
assetClass: "ETH",
},
priceDecimal: "0.000000000000000002",
priceDecimal: "0.0002",
payouts: [],
originFees: [],
end: Date.now() + 1000 * 60 * 60 * 24 * 30,
Expand Down Expand Up @@ -162,4 +162,5 @@ describe.skip("get buy transaction", () => {
})

})

})