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

Feature/dev 717 add optional wait for transaction in sdk actions #446

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
41 changes: 24 additions & 17 deletions packages/core/src/actions/order/cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import {
import { Config } from "../../createConfig.js";
import { CancelInfo, FullCancelInfo } from "../../types/index.js";

export interface CancelOrderParameters {
starknetAccount: AccountInterface;
cancelInfo: CancelInfo;
waitForTransaction?: boolean;
}

export interface CancelOrderResult {
transactionHash: string;
}

/**
* Executes a transaction to cancel an order on the Arkchain.
*
Expand All @@ -19,7 +29,7 @@ import { CancelInfo, FullCancelInfo } from "../../types/index.js";
* including data compilation, signing, and transaction execution.
*
* @param {Config} config - The core SDK configuration, including network and contract details.
* @param {cancelOrderParameters} parameters - The parameters required to cancel an order, including:
* @param {CancelOrderParameters} parameters - The parameters required to cancel an order, including:
* - starknetAccount: The Starknet account used for signing the transaction.
* - arkAccount: The Arkchain account used to execute the cancellation transaction.
* - cancelInfo: Information about the order to be cancelled, including the order hash and token details.
Expand All @@ -29,16 +39,11 @@ import { CancelInfo, FullCancelInfo } from "../../types/index.js";
*
* @throws {Error} Throws an error if the contract ABI is not found or if the transaction fails.
*/
interface cancelOrderParameters {
starknetAccount: AccountInterface;
cancelInfo: CancelInfo;
}

const cancelOrder = async (
export async function cancelOrder(
config: Config,
parameters: cancelOrderParameters
) => {
const { starknetAccount, cancelInfo } = parameters;
parameters: CancelOrderParameters
): Promise<CancelOrderResult> {
const { starknetAccount, cancelInfo, waitForTransaction = true } = parameters;
const chainId = await config.starknetProvider.getChainId();
const fullCancelInfo: FullCancelInfo = {
orderHash: cancelInfo.orderHash,
Expand All @@ -51,7 +56,6 @@ const cancelOrder = async (
)
};

// Execute the transaction
const result = await starknetAccount.execute({
contractAddress: config.starknetExecutorContract,
entrypoint: "cancel_order",
Expand All @@ -60,10 +64,13 @@ const cancelOrder = async (
})
});

// Wait for the transaction to be processed
await config.starknetProvider.waitForTransaction(result.transaction_hash, {
retryInterval: 1000
});
};
if (waitForTransaction) {
await config.starknetProvider.waitForTransaction(result.transaction_hash, {
retryInterval: 1000
});
}

export { cancelOrder };
return {
transactionHash: result.transaction_hash
};
}
36 changes: 25 additions & 11 deletions packages/core/src/actions/order/createAuction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ import {
} from "../../types/index.js";
import { getOrderHashFromOrderV1 } from "../../utils/index.js";

interface CreateAuctionParameters {
export interface CreateAuctionParameters {
starknetAccount: AccountInterface;
order: AuctionV1;
approveInfo: ApproveErc721Info;
waitForTransaction?: boolean;
}

export interface CreateAuctionResult {
orderHash: bigint;
transactionHash: string;
}

/**
Expand All @@ -36,11 +42,16 @@ interface CreateAuctionParameters {
* @returns {Promise<string>} A promise that resolves with the hash of the created order.
*
*/
const createAuction = async (
export async function createAuction(
config: Config,
parameters: CreateAuctionParameters
) => {
const { starknetAccount, order: baseOrder, approveInfo } = parameters;
): Promise<CreateAuctionResult> {
const {
starknetAccount,
order: baseOrder,
approveInfo,
waitForTransaction = true
} = parameters;
const currentDate = new Date();
currentDate.setDate(currentDate.getDate());
const startDate = baseOrder.startDate || Math.floor(Date.now() / 1000);
Expand Down Expand Up @@ -105,13 +116,16 @@ const createAuction = async (
}
]);

await config.starknetProvider.waitForTransaction(result.transaction_hash, {
retryInterval: 1000
});
if (waitForTransaction) {
await config.starknetProvider.waitForTransaction(result.transaction_hash, {
retryInterval: 1000
});
}

const orderHash = getOrderHashFromOrderV1(order);

return orderHash;
};

export { createAuction };
return {
orderHash,
transactionHash: result.transaction_hash
};
}
36 changes: 25 additions & 11 deletions packages/core/src/actions/order/createListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ import {
} from "../../types/index.js";
import { getOrderHashFromOrderV1 } from "../../utils/index.js";

interface CreateListingParameters {
export interface CreateListingParameters {
starknetAccount: AccountInterface;
order: ListingV1;
approveInfo: ApproveErc721Info;
waitForTransaction?: boolean;
}

export interface CreateListingResult {
orderHash: bigint;
transactionHash: string;
}

/**
Expand All @@ -36,11 +42,16 @@ interface CreateListingParameters {
* @returns {Promise<string>} A promise that resolves with the hash of the created order.
*
*/
const createListing = async (
export async function createListing(
config: Config,
parameters: CreateListingParameters
) => {
const { starknetAccount, order: baseOrder, approveInfo } = parameters;
): Promise<CreateListingResult> {
const {
starknetAccount,
order: baseOrder,
approveInfo,
waitForTransaction = true
} = parameters;
const currentDate = new Date();
currentDate.setDate(currentDate.getDate());
const startDate = baseOrder.startDate || Math.floor(Date.now() / 1000);
Expand Down Expand Up @@ -89,13 +100,16 @@ const createListing = async (
}
]);

await config.starknetProvider.waitForTransaction(result.transaction_hash, {
retryInterval: 1000
});
if (waitForTransaction) {
await config.starknetProvider.waitForTransaction(result.transaction_hash, {
retryInterval: 1000
});
}

const orderHash = getOrderHashFromOrderV1(order);

return orderHash;
};

export { createListing };
return {
orderHash,
transactionHash: result.transaction_hash
};
}
38 changes: 26 additions & 12 deletions packages/core/src/actions/order/createOffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ import {
import { getOrderHashFromOrderV1 } from "../../utils/index.js";
import { getAllowance } from "../read/getAllowance.js";

interface CreateOfferParameters {
export interface CreateOfferParameters {
starknetAccount: AccountInterface;
offer: OfferV1;
approveInfo: ApproveErc20Info;
waitForTransaction?: boolean;
}

export interface CreateOfferResult {
orderHash: bigint;
transactionHash: string;
}

/**
Expand All @@ -34,14 +40,19 @@ interface CreateOfferParameters {
* @param {CreateListingParameters} parameters - The parameters for the listing, including Starknet account,
* Arkchain account, base order details, and an optional owner address.
*
* @returns {Promise<string>} A promise that resolves with the hash of the created order.
* @returns {Promise<CreateOfferResult>} A promise that resolves with the hash of the created order.
*
*/
const createOffer = async (
export async function createOffer(
config: Config,
parameters: CreateOfferParameters
) => {
const { starknetAccount, offer: baseOrder, approveInfo } = parameters;
): Promise<CreateOfferResult> {
const {
starknetAccount,
offer: baseOrder,
approveInfo,
waitForTransaction = true
} = parameters;
const currentDate = new Date();
currentDate.setDate(currentDate.getDate());
const startDate = baseOrder.startDate || Math.floor(Date.now() / 1000);
Expand Down Expand Up @@ -101,13 +112,16 @@ const createOffer = async (
}
]);

await config.starknetProvider.waitForTransaction(result.transaction_hash, {
retryInterval: 1000
});
if (waitForTransaction) {
await config.starknetProvider.waitForTransaction(result.transaction_hash, {
retryInterval: 1000
});
}

const orderHash = getOrderHashFromOrderV1(order);

return orderHash;
};

export { createOffer };
return {
orderHash,
transactionHash: result.transaction_hash
};
}
39 changes: 26 additions & 13 deletions packages/core/src/actions/order/fulfillAuction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import {
import { Config } from "../../createConfig.js";
import { FulfillAuctionInfo, FulfillInfo } from "../../types/index.js";

export interface FulfillAuctionParameters {
starknetAccount: AccountInterface;
fulfillAuctionInfo: FulfillAuctionInfo;
waitForTransaction?: boolean;
}

export interface FulfillAuctionResult {
transactionHash: string;
}

/**
* Fulfill an auction on the Arkchain.
*
Expand All @@ -18,16 +28,15 @@ import { FulfillAuctionInfo, FulfillInfo } from "../../types/index.js";
*
* @returns {Promise<void>} A promise that resolves when the transaction is completed.
*/
interface FulfillAuctionParameters {
starknetAccount: AccountInterface;
fulfillAuctionInfo: FulfillAuctionInfo;
}

const fulfillAuction = async (
export async function fulfillAuction(
config: Config,
parameters: FulfillAuctionParameters
) => {
const { starknetAccount, fulfillAuctionInfo } = parameters;
): Promise<FulfillAuctionResult> {
const {
starknetAccount,
fulfillAuctionInfo,
waitForTransaction = true
} = parameters;
const chainId = await config.starknetProvider.getChainId();

const fulfillInfo: FulfillInfo = {
Expand Down Expand Up @@ -56,9 +65,13 @@ const fulfillAuction = async (
}
]);

await config.starknetProvider.waitForTransaction(result.transaction_hash, {
retryInterval: 1000
});
};
if (waitForTransaction) {
await config.starknetProvider.waitForTransaction(result.transaction_hash, {
retryInterval: 1000
});
}

export { fulfillAuction };
return {
transactionHash: result.transaction_hash
};
}
45 changes: 29 additions & 16 deletions packages/core/src/actions/order/fulfillListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,35 @@ import {
} from "../../types/index.js";
import { getAllowance } from "../read/getAllowance.js";

export interface FulfillListingParameters {
starknetAccount: AccountInterface;
fulfillListingInfo: FulfillListingInfo;
approveInfo: ApproveErc20Info;
waitForTransaction?: boolean;
}

export type FulfillListingResult = {
transactionHash: string;
};

/**
* Fulfill a listing on the Arkchain.
*
* @param {Config} config - The core SDK configuration.
* @param {FulfillListingParameters} parameters - Parameters for fulfilling the listing.
*
* @returns {Promise<void>} A promise that resolves when the transaction is completed.
* @returns {Promise<FulfillListingResult>} A promise that resolves when the transaction is completed.
*/
interface FulfillListingParameters {
starknetAccount: AccountInterface;
fulfillListingInfo: FulfillListingInfo;
approveInfo: ApproveErc20Info;
}

const fulfillListing = async (
export async function fulfillListing(
config: Config,
parameters: FulfillListingParameters
) => {
const { starknetAccount, fulfillListingInfo, approveInfo } = parameters;
): Promise<FulfillListingResult> {
const {
starknetAccount,
fulfillListingInfo,
approveInfo,
waitForTransaction = true
} = parameters;
const chainId = await config.starknetProvider.getChainId();
const currentAllowance = await getAllowance(
config,
Expand Down Expand Up @@ -73,10 +83,13 @@ const fulfillListing = async (
}
]);

// Wait for the transaction to be processed
await config.starknetProvider.waitForTransaction(result.transaction_hash, {
retryInterval: 1000
});
};
if (waitForTransaction) {
await config.starknetProvider.waitForTransaction(result.transaction_hash, {
retryInterval: 1000
});
}

export { fulfillListing };
return {
transactionHash: result.transaction_hash
};
}
Loading
Loading