@railblock/opencommodity-sdk 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +23 -7
- package/dist/index.d.ts +23 -7
- package/dist/index.js +24 -40
- package/dist/index.mjs +24 -40
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -117,6 +117,20 @@ interface CreateListingParams {
|
|
|
117
117
|
price: number;
|
|
118
118
|
gcid?: string;
|
|
119
119
|
}
|
|
120
|
+
interface CreateEscrowSaleParams {
|
|
121
|
+
tokenId: number;
|
|
122
|
+
amount: number;
|
|
123
|
+
price: number;
|
|
124
|
+
seller: string;
|
|
125
|
+
}
|
|
126
|
+
interface ConfirmEscrowActionParams {
|
|
127
|
+
saleId: string | number;
|
|
128
|
+
}
|
|
129
|
+
interface ResolveEscrowDisputeParams {
|
|
130
|
+
saleId: string | number;
|
|
131
|
+
favorBuyer: boolean;
|
|
132
|
+
refundPercentage: number;
|
|
133
|
+
}
|
|
120
134
|
|
|
121
135
|
declare class OpenCommodityError extends Error {
|
|
122
136
|
status: number;
|
|
@@ -153,13 +167,15 @@ declare class OpenCommodityClient {
|
|
|
153
167
|
getStats(): Promise<ProtocolStats>;
|
|
154
168
|
createCommodity(params: CreateCommodityParams): Promise<Commodity>;
|
|
155
169
|
createListing(params: CreateListingParams): Promise<Listing>;
|
|
156
|
-
createUniversalEscrowSale(params:
|
|
157
|
-
confirmUniversalEscrowShipment(
|
|
158
|
-
confirmUniversalEscrowReceipt(
|
|
159
|
-
acceptUniversalEscrowQuality(
|
|
160
|
-
initiateUniversalEscrowDispute(
|
|
161
|
-
|
|
162
|
-
|
|
170
|
+
createUniversalEscrowSale(params: CreateEscrowSaleParams): Promise<string>;
|
|
171
|
+
confirmUniversalEscrowShipment(params: ConfirmEscrowActionParams): Promise<string>;
|
|
172
|
+
confirmUniversalEscrowReceipt(params: ConfirmEscrowActionParams): Promise<string>;
|
|
173
|
+
acceptUniversalEscrowQuality(params: ConfirmEscrowActionParams): Promise<string>;
|
|
174
|
+
initiateUniversalEscrowDispute(params: ConfirmEscrowActionParams & {
|
|
175
|
+
reason: string;
|
|
176
|
+
}): Promise<string>;
|
|
177
|
+
resolveUniversalEscrowDispute(params: ResolveEscrowDisputeParams): Promise<string>;
|
|
178
|
+
autoReleaseUniversalEscrowFunds(params: ConfirmEscrowActionParams): Promise<string>;
|
|
163
179
|
private hasUniversalEscrowContract;
|
|
164
180
|
private callUniversalEscrowContract;
|
|
165
181
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -117,6 +117,20 @@ interface CreateListingParams {
|
|
|
117
117
|
price: number;
|
|
118
118
|
gcid?: string;
|
|
119
119
|
}
|
|
120
|
+
interface CreateEscrowSaleParams {
|
|
121
|
+
tokenId: number;
|
|
122
|
+
amount: number;
|
|
123
|
+
price: number;
|
|
124
|
+
seller: string;
|
|
125
|
+
}
|
|
126
|
+
interface ConfirmEscrowActionParams {
|
|
127
|
+
saleId: string | number;
|
|
128
|
+
}
|
|
129
|
+
interface ResolveEscrowDisputeParams {
|
|
130
|
+
saleId: string | number;
|
|
131
|
+
favorBuyer: boolean;
|
|
132
|
+
refundPercentage: number;
|
|
133
|
+
}
|
|
120
134
|
|
|
121
135
|
declare class OpenCommodityError extends Error {
|
|
122
136
|
status: number;
|
|
@@ -153,13 +167,15 @@ declare class OpenCommodityClient {
|
|
|
153
167
|
getStats(): Promise<ProtocolStats>;
|
|
154
168
|
createCommodity(params: CreateCommodityParams): Promise<Commodity>;
|
|
155
169
|
createListing(params: CreateListingParams): Promise<Listing>;
|
|
156
|
-
createUniversalEscrowSale(params:
|
|
157
|
-
confirmUniversalEscrowShipment(
|
|
158
|
-
confirmUniversalEscrowReceipt(
|
|
159
|
-
acceptUniversalEscrowQuality(
|
|
160
|
-
initiateUniversalEscrowDispute(
|
|
161
|
-
|
|
162
|
-
|
|
170
|
+
createUniversalEscrowSale(params: CreateEscrowSaleParams): Promise<string>;
|
|
171
|
+
confirmUniversalEscrowShipment(params: ConfirmEscrowActionParams): Promise<string>;
|
|
172
|
+
confirmUniversalEscrowReceipt(params: ConfirmEscrowActionParams): Promise<string>;
|
|
173
|
+
acceptUniversalEscrowQuality(params: ConfirmEscrowActionParams): Promise<string>;
|
|
174
|
+
initiateUniversalEscrowDispute(params: ConfirmEscrowActionParams & {
|
|
175
|
+
reason: string;
|
|
176
|
+
}): Promise<string>;
|
|
177
|
+
resolveUniversalEscrowDispute(params: ResolveEscrowDisputeParams): Promise<string>;
|
|
178
|
+
autoReleaseUniversalEscrowFunds(params: ConfirmEscrowActionParams): Promise<string>;
|
|
163
179
|
private hasUniversalEscrowContract;
|
|
164
180
|
private callUniversalEscrowContract;
|
|
165
181
|
}
|
package/dist/index.js
CHANGED
|
@@ -27548,55 +27548,39 @@ var OpenCommodityClient = class {
|
|
|
27548
27548
|
});
|
|
27549
27549
|
}
|
|
27550
27550
|
async createUniversalEscrowSale(params) {
|
|
27551
|
-
if (this.hasUniversalEscrowContract()) {
|
|
27552
|
-
|
|
27553
|
-
params.token_id,
|
|
27554
|
-
params.amount,
|
|
27555
|
-
params.price,
|
|
27556
|
-
params.seller_wallet
|
|
27557
|
-
]);
|
|
27558
|
-
return {
|
|
27559
|
-
id: String(saleId),
|
|
27560
|
-
commodity_id: params.commodity_id,
|
|
27561
|
-
seller_wallet: params.seller_wallet,
|
|
27562
|
-
buyer_wallet: params.buyer_wallet,
|
|
27563
|
-
price: params.price,
|
|
27564
|
-
amount: params.amount,
|
|
27565
|
-
status: "FUNDED",
|
|
27566
|
-
gcid: null,
|
|
27567
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
27568
|
-
};
|
|
27551
|
+
if (!this.hasUniversalEscrowContract()) {
|
|
27552
|
+
throw new Error("universalEscrow contract configuration is required");
|
|
27569
27553
|
}
|
|
27570
|
-
|
|
27554
|
+
const saleId = await this.callUniversalEscrowContract("createSale", [
|
|
27555
|
+
params.tokenId,
|
|
27556
|
+
params.amount,
|
|
27557
|
+
params.price,
|
|
27558
|
+
params.seller
|
|
27559
|
+
], "SaleCreated");
|
|
27560
|
+
return String(saleId);
|
|
27571
27561
|
}
|
|
27572
|
-
async confirmUniversalEscrowShipment(
|
|
27573
|
-
|
|
27574
|
-
return this.getSale(String(saleId));
|
|
27562
|
+
async confirmUniversalEscrowShipment(params) {
|
|
27563
|
+
return this.callUniversalEscrowContract("confirmShipment", [params.saleId], "Shipped");
|
|
27575
27564
|
}
|
|
27576
|
-
async confirmUniversalEscrowReceipt(
|
|
27577
|
-
|
|
27578
|
-
return this.getSale(String(saleId));
|
|
27565
|
+
async confirmUniversalEscrowReceipt(params) {
|
|
27566
|
+
return this.callUniversalEscrowContract("confirmReceipt", [params.saleId], "ReceiptConfirmed");
|
|
27579
27567
|
}
|
|
27580
|
-
async acceptUniversalEscrowQuality(
|
|
27581
|
-
|
|
27582
|
-
return this.getSale(String(saleId));
|
|
27568
|
+
async acceptUniversalEscrowQuality(params) {
|
|
27569
|
+
return this.callUniversalEscrowContract("acceptQuality", [params.saleId], "QualityAccepted");
|
|
27583
27570
|
}
|
|
27584
|
-
async initiateUniversalEscrowDispute(
|
|
27585
|
-
|
|
27586
|
-
return this.getSale(String(saleId));
|
|
27571
|
+
async initiateUniversalEscrowDispute(params) {
|
|
27572
|
+
return this.callUniversalEscrowContract("initiateDispute", [params.saleId, params.reason], "DisputeInitiated");
|
|
27587
27573
|
}
|
|
27588
|
-
async resolveUniversalEscrowDispute(
|
|
27589
|
-
|
|
27590
|
-
return this.getSale(String(saleId));
|
|
27574
|
+
async resolveUniversalEscrowDispute(params) {
|
|
27575
|
+
return this.callUniversalEscrowContract("resolveDispute", [params.saleId, params.favorBuyer, params.refundPercentage], "DisputeResolved");
|
|
27591
27576
|
}
|
|
27592
|
-
async autoReleaseUniversalEscrowFunds(
|
|
27593
|
-
|
|
27594
|
-
return this.getSale(String(saleId));
|
|
27577
|
+
async autoReleaseUniversalEscrowFunds(params) {
|
|
27578
|
+
return this.callUniversalEscrowContract("autoReleaseFunds", [params.saleId], "AutoReleased");
|
|
27595
27579
|
}
|
|
27596
27580
|
hasUniversalEscrowContract() {
|
|
27597
27581
|
return !!(this.provider && this.contracts?.universalEscrow);
|
|
27598
27582
|
}
|
|
27599
|
-
async callUniversalEscrowContract(method, args) {
|
|
27583
|
+
async callUniversalEscrowContract(method, args, eventName) {
|
|
27600
27584
|
if (!this.hasUniversalEscrowContract()) {
|
|
27601
27585
|
throw new Error("universalEscrow contract configuration is required");
|
|
27602
27586
|
}
|
|
@@ -27614,8 +27598,8 @@ var OpenCommodityClient = class {
|
|
|
27614
27598
|
} catch {
|
|
27615
27599
|
return null;
|
|
27616
27600
|
}
|
|
27617
|
-
}).find((e) => e?.name ===
|
|
27618
|
-
return event?.args?.saleId ?? receipt.hash;
|
|
27601
|
+
}).find((e) => e?.name === eventName);
|
|
27602
|
+
return String(event?.args?.saleId ?? receipt.hash);
|
|
27619
27603
|
}
|
|
27620
27604
|
};
|
|
27621
27605
|
|
package/dist/index.mjs
CHANGED
|
@@ -27540,55 +27540,39 @@ var OpenCommodityClient = class {
|
|
|
27540
27540
|
});
|
|
27541
27541
|
}
|
|
27542
27542
|
async createUniversalEscrowSale(params) {
|
|
27543
|
-
if (this.hasUniversalEscrowContract()) {
|
|
27544
|
-
|
|
27545
|
-
params.token_id,
|
|
27546
|
-
params.amount,
|
|
27547
|
-
params.price,
|
|
27548
|
-
params.seller_wallet
|
|
27549
|
-
]);
|
|
27550
|
-
return {
|
|
27551
|
-
id: String(saleId),
|
|
27552
|
-
commodity_id: params.commodity_id,
|
|
27553
|
-
seller_wallet: params.seller_wallet,
|
|
27554
|
-
buyer_wallet: params.buyer_wallet,
|
|
27555
|
-
price: params.price,
|
|
27556
|
-
amount: params.amount,
|
|
27557
|
-
status: "FUNDED",
|
|
27558
|
-
gcid: null,
|
|
27559
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
27560
|
-
};
|
|
27543
|
+
if (!this.hasUniversalEscrowContract()) {
|
|
27544
|
+
throw new Error("universalEscrow contract configuration is required");
|
|
27561
27545
|
}
|
|
27562
|
-
|
|
27546
|
+
const saleId = await this.callUniversalEscrowContract("createSale", [
|
|
27547
|
+
params.tokenId,
|
|
27548
|
+
params.amount,
|
|
27549
|
+
params.price,
|
|
27550
|
+
params.seller
|
|
27551
|
+
], "SaleCreated");
|
|
27552
|
+
return String(saleId);
|
|
27563
27553
|
}
|
|
27564
|
-
async confirmUniversalEscrowShipment(
|
|
27565
|
-
|
|
27566
|
-
return this.getSale(String(saleId));
|
|
27554
|
+
async confirmUniversalEscrowShipment(params) {
|
|
27555
|
+
return this.callUniversalEscrowContract("confirmShipment", [params.saleId], "Shipped");
|
|
27567
27556
|
}
|
|
27568
|
-
async confirmUniversalEscrowReceipt(
|
|
27569
|
-
|
|
27570
|
-
return this.getSale(String(saleId));
|
|
27557
|
+
async confirmUniversalEscrowReceipt(params) {
|
|
27558
|
+
return this.callUniversalEscrowContract("confirmReceipt", [params.saleId], "ReceiptConfirmed");
|
|
27571
27559
|
}
|
|
27572
|
-
async acceptUniversalEscrowQuality(
|
|
27573
|
-
|
|
27574
|
-
return this.getSale(String(saleId));
|
|
27560
|
+
async acceptUniversalEscrowQuality(params) {
|
|
27561
|
+
return this.callUniversalEscrowContract("acceptQuality", [params.saleId], "QualityAccepted");
|
|
27575
27562
|
}
|
|
27576
|
-
async initiateUniversalEscrowDispute(
|
|
27577
|
-
|
|
27578
|
-
return this.getSale(String(saleId));
|
|
27563
|
+
async initiateUniversalEscrowDispute(params) {
|
|
27564
|
+
return this.callUniversalEscrowContract("initiateDispute", [params.saleId, params.reason], "DisputeInitiated");
|
|
27579
27565
|
}
|
|
27580
|
-
async resolveUniversalEscrowDispute(
|
|
27581
|
-
|
|
27582
|
-
return this.getSale(String(saleId));
|
|
27566
|
+
async resolveUniversalEscrowDispute(params) {
|
|
27567
|
+
return this.callUniversalEscrowContract("resolveDispute", [params.saleId, params.favorBuyer, params.refundPercentage], "DisputeResolved");
|
|
27583
27568
|
}
|
|
27584
|
-
async autoReleaseUniversalEscrowFunds(
|
|
27585
|
-
|
|
27586
|
-
return this.getSale(String(saleId));
|
|
27569
|
+
async autoReleaseUniversalEscrowFunds(params) {
|
|
27570
|
+
return this.callUniversalEscrowContract("autoReleaseFunds", [params.saleId], "AutoReleased");
|
|
27587
27571
|
}
|
|
27588
27572
|
hasUniversalEscrowContract() {
|
|
27589
27573
|
return !!(this.provider && this.contracts?.universalEscrow);
|
|
27590
27574
|
}
|
|
27591
|
-
async callUniversalEscrowContract(method, args) {
|
|
27575
|
+
async callUniversalEscrowContract(method, args, eventName) {
|
|
27592
27576
|
if (!this.hasUniversalEscrowContract()) {
|
|
27593
27577
|
throw new Error("universalEscrow contract configuration is required");
|
|
27594
27578
|
}
|
|
@@ -27606,8 +27590,8 @@ var OpenCommodityClient = class {
|
|
|
27606
27590
|
} catch {
|
|
27607
27591
|
return null;
|
|
27608
27592
|
}
|
|
27609
|
-
}).find((e) => e?.name ===
|
|
27610
|
-
return event?.args?.saleId ?? receipt.hash;
|
|
27593
|
+
}).find((e) => e?.name === eventName);
|
|
27594
|
+
return String(event?.args?.saleId ?? receipt.hash);
|
|
27611
27595
|
}
|
|
27612
27596
|
};
|
|
27613
27597
|
|