@tradeport/sui-trading-sdk 0.1.23 → 0.1.25
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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +149 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +149 -72
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +2 -2
- package/src/methods/acceptCollectionBid/acceptCollectionBid.ts +11 -1
- package/src/methods/acceptNftBids/acceptNftBids.ts +4 -1
- package/src/methods/acceptNftBids/addAcceptNftBidTxs.ts +3 -0
- package/src/methods/buyListings/addBuyListingTxs.ts +12 -2
- package/src/methods/buyListings/buyListings.ts +12 -2
- package/src/methods/buyLocks/buyLocks.ts +1 -2
- package/src/methods/createLongLocks/createLongLocks.ts +10 -0
- package/src/methods/createShortLocks/createShortLocks.ts +3 -4
- package/src/methods/exerciseLongLocks/exerciseLongLocks.ts +47 -7
- package/src/methods/exerciseShortLocks/exerciseShortLocks.ts +41 -31
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -11,6 +11,7 @@ type AcceptNftBids = {
|
|
|
11
11
|
bidIds: string[];
|
|
12
12
|
tx?: Transaction;
|
|
13
13
|
kioskTx?: KioskTransaction;
|
|
14
|
+
beforeResolveKioskTransferRequest?: (transferRequest: any) => void | Promise<void>;
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
type BuyAndExerciseLongLocks = {
|
|
@@ -27,6 +28,7 @@ type BuyListings = {
|
|
|
27
28
|
walletAddress: string;
|
|
28
29
|
tx?: Transaction;
|
|
29
30
|
kioskTx?: KioskTransaction;
|
|
31
|
+
beforeResolveKioskTransferRequest?: (transferRequest: any) => void | Promise<void>;
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
type BuyLocks = {
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ type AcceptNftBids = {
|
|
|
11
11
|
bidIds: string[];
|
|
12
12
|
tx?: Transaction;
|
|
13
13
|
kioskTx?: KioskTransaction;
|
|
14
|
+
beforeResolveKioskTransferRequest?: (transferRequest: any) => void | Promise<void>;
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
type BuyAndExerciseLongLocks = {
|
|
@@ -27,6 +28,7 @@ type BuyListings = {
|
|
|
27
28
|
walletAddress: string;
|
|
28
29
|
tx?: Transaction;
|
|
29
30
|
kioskTx?: KioskTransaction;
|
|
31
|
+
beforeResolveKioskTransferRequest?: (transferRequest: any) => void | Promise<void>;
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
type BuyLocks = {
|
package/dist/index.js
CHANGED
|
@@ -200,8 +200,8 @@ var TRADEPORT_KIOSK_TRANSFERS_ESCROW_KIOSK = "0xa677dab85a93bd8d6845b6cc7914f3bb
|
|
|
200
200
|
var TRADEPORT_KIOSK_BIDDING_STORE = "0x1e5e7f38e3a61d1d189506d0fc6b7e47e935a292d9e1b23c0f3f1c0f94227772";
|
|
201
201
|
var TRADEPORT_KIOSK_BIDDING_ESCROW_KIOSK = "0x151fbe627d3f8de855f424c879ea2176d89282185a4b9226a7157172dd2919cc";
|
|
202
202
|
var TRADEPORT_KIOSK_BID_NONCE_TYPE = "0xec175e537be9e48f75fa6929291de6454d2502f1091feb22c0d26a22821bbf28::kiosk_biddings::Bid";
|
|
203
|
-
var TRADEPORT_PRICE_LOCK_PACKAGE = "
|
|
204
|
-
var TRADEPORT_PRICE_LOCK_STORE = "
|
|
203
|
+
var TRADEPORT_PRICE_LOCK_PACKAGE = "0x027c64473c0b9bc5364a22a08e7fc9af059151433b4e631c4baf25f540426977";
|
|
204
|
+
var TRADEPORT_PRICE_LOCK_STORE = "0xaf60ed2cb8c671dcc27e5721371869f0ae9c508297a011716244b50ec12d02a1";
|
|
205
205
|
var COLLECTION_IDS_WITH_ZERO_COMMISSION = [
|
|
206
206
|
""
|
|
207
207
|
];
|
|
@@ -243,7 +243,6 @@ var MASC_ROYALTY_DECIMAL_PERCENT = 0.085;
|
|
|
243
243
|
var BASC_ROYALTY_DECIMAL_PERCENT = 0.055;
|
|
244
244
|
var DSL_LEGACY_ROYALTY_DECIMAL_PERCENT = 0.05;
|
|
245
245
|
var PREMIUM_NOMINATOR = 300n;
|
|
246
|
-
var PREMIUM_FEE_NOMINATOR = 2500n;
|
|
247
246
|
var ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK = [
|
|
248
247
|
"0xc4fc5b341858ac6fff4859d8105e345b195847cd230e8538d61a2f319ae8093c::bluemove_launchpad::GOATsOfSui"
|
|
249
248
|
];
|
|
@@ -870,7 +869,8 @@ async function addTradeportKioskAcceptNftBidTx({
|
|
|
870
869
|
nftTokenId,
|
|
871
870
|
nftType,
|
|
872
871
|
royaltyRulePackageId,
|
|
873
|
-
royaltyRuleModule
|
|
872
|
+
royaltyRuleModule,
|
|
873
|
+
beforeResolveKioskTransferRequest
|
|
874
874
|
}) {
|
|
875
875
|
const { transferPolicy } = sharedObjects;
|
|
876
876
|
const [feeCoin, transferRequest] = tx.moveCall({
|
|
@@ -889,6 +889,7 @@ async function addTradeportKioskAcceptNftBidTx({
|
|
|
889
889
|
typeArguments: [nftType],
|
|
890
890
|
arguments: [tx.object(transferPolicy), transferRequest, feeCoin]
|
|
891
891
|
});
|
|
892
|
+
await beforeResolveKioskTransferRequest?.(transferRequest);
|
|
892
893
|
await resolveTransferPolicies({
|
|
893
894
|
tx,
|
|
894
895
|
kioskTx,
|
|
@@ -1501,7 +1502,14 @@ function addTocenAcceptCollectionBidTxHandler(txData) {
|
|
|
1501
1502
|
|
|
1502
1503
|
// src/methods/acceptCollectionBid/acceptCollectionBid.ts
|
|
1503
1504
|
var ERROR_UNLIST_FIRST = "Item must be unlisted first before you can accept a collection bid with it";
|
|
1504
|
-
var acceptCollectionBid = async ({
|
|
1505
|
+
var acceptCollectionBid = async ({
|
|
1506
|
+
bid,
|
|
1507
|
+
nftId,
|
|
1508
|
+
walletAddress,
|
|
1509
|
+
tx: existingTx,
|
|
1510
|
+
kioskTx,
|
|
1511
|
+
beforeResolveKioskTransferRequest
|
|
1512
|
+
}, context) => {
|
|
1505
1513
|
const nftRes = await gqlChainRequest({
|
|
1506
1514
|
chain: "sui",
|
|
1507
1515
|
query: fetchNftById,
|
|
@@ -1532,7 +1540,8 @@ var acceptCollectionBid = async ({ bid, nftId, walletAddress, tx: existingTx, ki
|
|
|
1532
1540
|
sellerKiosk: nft?.chain_state?.kiosk_id,
|
|
1533
1541
|
collectionId: nft?.collection_id,
|
|
1534
1542
|
isListedOnBluemove: nft?.listings?.[0]?.market_name === "bluemove",
|
|
1535
|
-
bidMarketName: bid?.market_contract?.name
|
|
1543
|
+
bidMarketName: bid?.market_contract?.name,
|
|
1544
|
+
beforeResolveKioskTransferRequest
|
|
1536
1545
|
};
|
|
1537
1546
|
switch (txData.bidMarketName) {
|
|
1538
1547
|
case "tradeport":
|
|
@@ -1607,7 +1616,7 @@ var fetchBidsById = import_graphql_request12.gql`
|
|
|
1607
1616
|
|
|
1608
1617
|
// src/methods/acceptNftBids/acceptNftBids.ts
|
|
1609
1618
|
var ERROR_UNLIST_FIRST2 = "Item must be unlisted first before you can accept a solo bid on it";
|
|
1610
|
-
var acceptNftBids = async ({ bidIds, tx: existingTx, kioskTx }, context) => {
|
|
1619
|
+
var acceptNftBids = async ({ bidIds, tx: existingTx, kioskTx, beforeResolveKioskTransferRequest }, context) => {
|
|
1611
1620
|
const res = await gqlChainRequest({
|
|
1612
1621
|
chain: "sui",
|
|
1613
1622
|
query: fetchBidsById,
|
|
@@ -1640,7 +1649,8 @@ var acceptNftBids = async ({ bidIds, tx: existingTx, kioskTx }, context) => {
|
|
|
1640
1649
|
bidAmount: bid?.price,
|
|
1641
1650
|
sellerKiosk: bid?.nft?.chain_state?.kiosk_id,
|
|
1642
1651
|
isListedOnBluemove: bid?.nft?.listings?.[0]?.market_name === "bluemove",
|
|
1643
|
-
bidMarketName: bid?.market_contract?.name
|
|
1652
|
+
bidMarketName: bid?.market_contract?.name,
|
|
1653
|
+
beforeResolveKioskTransferRequest
|
|
1644
1654
|
};
|
|
1645
1655
|
switch (txData.bidMarketName) {
|
|
1646
1656
|
case "tradeport":
|
|
@@ -1683,9 +1693,6 @@ var import_transactions3 = require("@mysten/sui/transactions");
|
|
|
1683
1693
|
function calculatePremium(price) {
|
|
1684
1694
|
return BigInt(price) * PREMIUM_NOMINATOR / 10000n;
|
|
1685
1695
|
}
|
|
1686
|
-
function calculatePremiumFee(premium) {
|
|
1687
|
-
return BigInt(premium) * PREMIUM_FEE_NOMINATOR / 10000n;
|
|
1688
|
-
}
|
|
1689
1696
|
|
|
1690
1697
|
// src/graphql/queries/fetchLockById.ts
|
|
1691
1698
|
var import_graphql_request13 = require("graphql-request");
|
|
@@ -1732,8 +1739,7 @@ async function buyLocks({ lockIds, transaction }) {
|
|
|
1732
1739
|
throw new Error(`Lock ${lockId} must be in active state`);
|
|
1733
1740
|
}
|
|
1734
1741
|
const premiumAmount = calculatePremium(lock.maker_price);
|
|
1735
|
-
const
|
|
1736
|
-
const [premium] = tx.splitCoins(tx.gas, [premiumAmount + premiumFee]);
|
|
1742
|
+
const [premium] = tx.splitCoins(tx.gas, [premiumAmount]);
|
|
1737
1743
|
tx.moveCall({
|
|
1738
1744
|
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::buy_lock`,
|
|
1739
1745
|
typeArguments: [lock.nft_type],
|
|
@@ -1850,11 +1856,11 @@ async function exerciseLongLocks({ walletAddress, transaction, locks }, context)
|
|
|
1850
1856
|
collectionId: lock.collection_id
|
|
1851
1857
|
})
|
|
1852
1858
|
);
|
|
1853
|
-
const [
|
|
1859
|
+
const [makerRewardWithFee] = tx.splitCoins(tx.gas, [
|
|
1854
1860
|
BigInt(lock.maker_price) + marketplaceFee
|
|
1855
1861
|
]);
|
|
1856
|
-
const [transferRequest] = tx.moveCall({
|
|
1857
|
-
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::
|
|
1862
|
+
const [transferRequest, confirmLockRequest] = tx.moveCall({
|
|
1863
|
+
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::start_confirm_long_lock`,
|
|
1858
1864
|
typeArguments: [lock.nft_type],
|
|
1859
1865
|
arguments: [
|
|
1860
1866
|
tx.object(TRADEPORT_PRICE_LOCK_STORE),
|
|
@@ -1863,9 +1869,7 @@ async function exerciseLongLocks({ walletAddress, transaction, locks }, context)
|
|
|
1863
1869
|
tx.object(lock.chain_state.makerKioskId),
|
|
1864
1870
|
tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
|
|
1865
1871
|
tx.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
|
|
1866
|
-
tx.object(transferPolicyId)
|
|
1867
|
-
tx.pure.u64(bid?.price ?? 0n),
|
|
1868
|
-
creatorRewardWithFee
|
|
1872
|
+
tx.object(transferPolicyId)
|
|
1869
1873
|
]
|
|
1870
1874
|
});
|
|
1871
1875
|
await resolveTransferPolicies({
|
|
@@ -1877,14 +1881,36 @@ async function exerciseLongLocks({ walletAddress, transaction, locks }, context)
|
|
|
1877
1881
|
shouldSkipKioskLocking: true
|
|
1878
1882
|
});
|
|
1879
1883
|
if (bid) {
|
|
1884
|
+
const beforeResolveKioskTransferRequest = (transferRequest2) => {
|
|
1885
|
+
tx.moveCall({
|
|
1886
|
+
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::end_confirm_long_lock_with_bid`,
|
|
1887
|
+
typeArguments: [lock.nft_type],
|
|
1888
|
+
arguments: [
|
|
1889
|
+
tx.object(TRADEPORT_PRICE_LOCK_STORE),
|
|
1890
|
+
confirmLockRequest,
|
|
1891
|
+
transferRequest2,
|
|
1892
|
+
makerRewardWithFee
|
|
1893
|
+
]
|
|
1894
|
+
});
|
|
1895
|
+
};
|
|
1880
1896
|
switch (bid.type) {
|
|
1881
1897
|
case "solo": {
|
|
1882
|
-
await acceptNftBids(
|
|
1898
|
+
await acceptNftBids(
|
|
1899
|
+
{ bidIds: [bidId], tx, kioskTx, beforeResolveKioskTransferRequest },
|
|
1900
|
+
context
|
|
1901
|
+
);
|
|
1883
1902
|
break;
|
|
1884
1903
|
}
|
|
1885
1904
|
case "collection": {
|
|
1886
1905
|
await acceptCollectionBid(
|
|
1887
|
-
{
|
|
1906
|
+
{
|
|
1907
|
+
bid,
|
|
1908
|
+
tx,
|
|
1909
|
+
nftId: lock.nft?.id,
|
|
1910
|
+
walletAddress,
|
|
1911
|
+
kioskTx,
|
|
1912
|
+
beforeResolveKioskTransferRequest
|
|
1913
|
+
},
|
|
1888
1914
|
context
|
|
1889
1915
|
);
|
|
1890
1916
|
break;
|
|
@@ -1893,6 +1919,25 @@ async function exerciseLongLocks({ walletAddress, transaction, locks }, context)
|
|
|
1893
1919
|
throw new Error(`Unsupported bid type ${bid.type}`);
|
|
1894
1920
|
}
|
|
1895
1921
|
}
|
|
1922
|
+
} else {
|
|
1923
|
+
const [transferRequest2] = tx.moveCall({
|
|
1924
|
+
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::end_confirm_long_lock`,
|
|
1925
|
+
typeArguments: [lock.nft_type],
|
|
1926
|
+
arguments: [
|
|
1927
|
+
tx.object(TRADEPORT_PRICE_LOCK_STORE),
|
|
1928
|
+
confirmLockRequest,
|
|
1929
|
+
tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
|
|
1930
|
+
makerRewardWithFee
|
|
1931
|
+
]
|
|
1932
|
+
});
|
|
1933
|
+
await resolveTransferPolicies({
|
|
1934
|
+
tx,
|
|
1935
|
+
kioskTx,
|
|
1936
|
+
nftType: lock.nft_type,
|
|
1937
|
+
price: lock.maker_price.toString(),
|
|
1938
|
+
transferRequest: transferRequest2,
|
|
1939
|
+
shouldSkipKioskLocking: true
|
|
1940
|
+
});
|
|
1896
1941
|
}
|
|
1897
1942
|
}
|
|
1898
1943
|
});
|
|
@@ -2024,9 +2069,12 @@ var addTradeportKioskBuyTx = async ({
|
|
|
2024
2069
|
nftType,
|
|
2025
2070
|
nftTokenId,
|
|
2026
2071
|
price,
|
|
2027
|
-
sellerKiosk
|
|
2072
|
+
sellerKiosk,
|
|
2073
|
+
collectionId,
|
|
2074
|
+
beforeResolveKioskTransferRequest
|
|
2028
2075
|
}) => {
|
|
2029
|
-
const
|
|
2076
|
+
const marketFeePrice = getMarketFeePrice({ price, collectionId });
|
|
2077
|
+
const [coin] = splitCoins({ tx, amounts: [tx.pure.u64(price + marketFeePrice)] });
|
|
2030
2078
|
if (!coin)
|
|
2031
2079
|
throw new Error("Coin could not be split");
|
|
2032
2080
|
const [kioskItem, transferRequest, kioskPrice] = tx.moveCall({
|
|
@@ -2040,6 +2088,7 @@ var addTradeportKioskBuyTx = async ({
|
|
|
2040
2088
|
],
|
|
2041
2089
|
typeArguments: [nftType]
|
|
2042
2090
|
});
|
|
2091
|
+
await beforeResolveKioskTransferRequest?.(transferRequest);
|
|
2043
2092
|
await resolveTransferPolicies({
|
|
2044
2093
|
tx,
|
|
2045
2094
|
kioskTx,
|
|
@@ -2091,7 +2140,8 @@ var addHyperspaceKioskBuyTx = async ({
|
|
|
2091
2140
|
nftType,
|
|
2092
2141
|
nftTokenId,
|
|
2093
2142
|
price,
|
|
2094
|
-
sellerKiosk
|
|
2143
|
+
sellerKiosk,
|
|
2144
|
+
beforeResolveKioskTransferRequest
|
|
2095
2145
|
}) => {
|
|
2096
2146
|
const [coin] = splitCoins({ tx, amounts: [tx.pure.u64(price)] });
|
|
2097
2147
|
if (!coin)
|
|
@@ -2111,6 +2161,7 @@ var addHyperspaceKioskBuyTx = async ({
|
|
|
2111
2161
|
transferRequest: hyperspaceMpTransferRequest
|
|
2112
2162
|
}
|
|
2113
2163
|
];
|
|
2164
|
+
await beforeResolveKioskTransferRequest?.(transferRequest);
|
|
2114
2165
|
await resolveTransferPolicies({
|
|
2115
2166
|
tx,
|
|
2116
2167
|
kioskTx,
|
|
@@ -2145,7 +2196,8 @@ async function addBluemoveKioskBuyTx({
|
|
|
2145
2196
|
nftTokenId,
|
|
2146
2197
|
nftType,
|
|
2147
2198
|
price,
|
|
2148
|
-
sellerKiosk
|
|
2199
|
+
sellerKiosk,
|
|
2200
|
+
beforeResolveKioskTransferRequest
|
|
2149
2201
|
}) {
|
|
2150
2202
|
const { transferPolicy } = sharedObjects;
|
|
2151
2203
|
const [coin1, coin2] = splitCoins({
|
|
@@ -2168,6 +2220,7 @@ async function addBluemoveKioskBuyTx({
|
|
|
2168
2220
|
],
|
|
2169
2221
|
typeArguments: [nftType]
|
|
2170
2222
|
});
|
|
2223
|
+
await beforeResolveKioskTransferRequest?.(transferRequest);
|
|
2171
2224
|
await resolveTransferPolicies({
|
|
2172
2225
|
tx,
|
|
2173
2226
|
kioskTx,
|
|
@@ -2395,7 +2448,13 @@ function addTocenBuyTxHandler(txData) {
|
|
|
2395
2448
|
}
|
|
2396
2449
|
|
|
2397
2450
|
// src/methods/buyListings/buyListings.ts
|
|
2398
|
-
var buyListings = async ({
|
|
2451
|
+
var buyListings = async ({
|
|
2452
|
+
listingIds,
|
|
2453
|
+
walletAddress,
|
|
2454
|
+
tx: existingTx,
|
|
2455
|
+
kioskTx,
|
|
2456
|
+
beforeResolveKioskTransferRequest
|
|
2457
|
+
}, context) => {
|
|
2399
2458
|
const res = await gqlChainRequest({
|
|
2400
2459
|
chain: "sui",
|
|
2401
2460
|
query: fetchListingsById,
|
|
@@ -2428,7 +2487,8 @@ var buyListings = async ({ listingIds, walletAddress, tx: existingTx, kioskTx },
|
|
|
2428
2487
|
price: listing?.price,
|
|
2429
2488
|
sellerKiosk: listing.nft?.chain_state?.kiosk_id,
|
|
2430
2489
|
collectionId: listing?.nft?.collection_id,
|
|
2431
|
-
nftContractId: listing?.nft?.contract_id
|
|
2490
|
+
nftContractId: listing?.nft?.contract_id,
|
|
2491
|
+
beforeResolveKioskTransferRequest
|
|
2432
2492
|
};
|
|
2433
2493
|
switch (listing?.market_name) {
|
|
2434
2494
|
case "tradeport":
|
|
@@ -2798,6 +2858,17 @@ var getActiveLockStateByNftId = async (nftId) => {
|
|
|
2798
2858
|
return res?.locks?.[0] ?? void 0;
|
|
2799
2859
|
};
|
|
2800
2860
|
|
|
2861
|
+
// src/helpers/calculateRoyaltyFee.ts
|
|
2862
|
+
function calculateRoyaltyFee(transferPolicyRules, price) {
|
|
2863
|
+
const royaltyRules = transferPolicyRules.filter(
|
|
2864
|
+
(rule) => rule.type === "royalty_rule"
|
|
2865
|
+
);
|
|
2866
|
+
return royaltyRules.reduce(
|
|
2867
|
+
(sum, rule) => sum + BigInt(rule.min_amount) + BigInt(rule.amount_bp) * price / 10000n,
|
|
2868
|
+
0n
|
|
2869
|
+
);
|
|
2870
|
+
}
|
|
2871
|
+
|
|
2801
2872
|
// src/methods/createLongLocks/createLongLocks.ts
|
|
2802
2873
|
async function createLongLocks({
|
|
2803
2874
|
walletAddress,
|
|
@@ -2820,6 +2891,11 @@ async function createLongLocks({
|
|
|
2820
2891
|
variables: { nftId: argNft.id }
|
|
2821
2892
|
}))?.nfts?.[0];
|
|
2822
2893
|
const nftType = getNftTypeFromNft(nft);
|
|
2894
|
+
const transferPolicy = (await getKioskTransferPolicies(nftType))?.at(0);
|
|
2895
|
+
if (!transferPolicy) {
|
|
2896
|
+
throw new Error(`Missing transfer policy for ${nftType}`);
|
|
2897
|
+
}
|
|
2898
|
+
const royalty = calculateRoyaltyFee(transferPolicy.rules, BigInt(argNft.priceInMist));
|
|
2823
2899
|
await kioskTxWrapper({
|
|
2824
2900
|
tx,
|
|
2825
2901
|
kioskOwner: walletAddress,
|
|
@@ -2842,6 +2918,7 @@ async function createLongLocks({
|
|
|
2842
2918
|
})
|
|
2843
2919
|
)
|
|
2844
2920
|
),
|
|
2921
|
+
tx.pure.u64(royalty),
|
|
2845
2922
|
tx.pure.u64(premium),
|
|
2846
2923
|
tx.pure.u64(expireIn)
|
|
2847
2924
|
]
|
|
@@ -2854,19 +2931,6 @@ async function createLongLocks({
|
|
|
2854
2931
|
|
|
2855
2932
|
// src/methods/createShortLocks/createShortLocks.ts
|
|
2856
2933
|
var import_transactions10 = require("@mysten/sui/transactions");
|
|
2857
|
-
|
|
2858
|
-
// src/helpers/calculateRoyaltyFee.ts
|
|
2859
|
-
function calculateRoyaltyFee(transferPolicyRules, price) {
|
|
2860
|
-
const royaltyRules = transferPolicyRules.filter(
|
|
2861
|
-
(rule) => rule.type === "royalty_rule"
|
|
2862
|
-
);
|
|
2863
|
-
return royaltyRules.reduce(
|
|
2864
|
-
(sum, rule) => sum + BigInt(rule.min_amount) + BigInt(rule.amount_bp) * price / 10000n,
|
|
2865
|
-
0n
|
|
2866
|
-
);
|
|
2867
|
-
}
|
|
2868
|
-
|
|
2869
|
-
// src/methods/createShortLocks/createShortLocks.ts
|
|
2870
2934
|
async function createShortLocks({ nfts }) {
|
|
2871
2935
|
const expireIn = 7 * 24 * 3600 * 1e3;
|
|
2872
2936
|
const tx = new import_transactions10.Transaction();
|
|
@@ -2885,10 +2949,9 @@ async function createShortLocks({ nfts }) {
|
|
|
2885
2949
|
collectionId: argNft.collectionId
|
|
2886
2950
|
})
|
|
2887
2951
|
);
|
|
2888
|
-
const
|
|
2889
|
-
calculateRoyaltyFee(transferPolicy.rules, BigInt(argNft.priceInMist));
|
|
2952
|
+
const royalty = calculateRoyaltyFee(transferPolicy.rules, BigInt(argNft.priceInMist));
|
|
2890
2953
|
const [deposit] = tx.splitCoins(tx.gas, [
|
|
2891
|
-
BigInt(argNft.priceInMist) +
|
|
2954
|
+
BigInt(argNft.priceInMist) + royalty + marketplaceFee
|
|
2892
2955
|
]);
|
|
2893
2956
|
tx.moveCall({
|
|
2894
2957
|
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::create_short_lock`,
|
|
@@ -2897,6 +2960,7 @@ async function createShortLocks({ nfts }) {
|
|
|
2897
2960
|
tx.object(TRADEPORT_PRICE_LOCK_STORE),
|
|
2898
2961
|
tx.pure.u64(BigInt(argNft.priceInMist)),
|
|
2899
2962
|
tx.pure.u64(marketplaceFee),
|
|
2963
|
+
tx.pure.u64(royalty),
|
|
2900
2964
|
tx.pure.u64(premium),
|
|
2901
2965
|
tx.pure.u64(expireIn),
|
|
2902
2966
|
deposit
|
|
@@ -2920,12 +2984,10 @@ async function exerciseShortLocks({ walletAddress, transaction, locks }, context
|
|
|
2920
2984
|
if (!transferPolicy) {
|
|
2921
2985
|
throw new Error(`Transfer policy is not found for ${lock.nft_type}`);
|
|
2922
2986
|
}
|
|
2923
|
-
const transferPolicyId = transferPolicy?.id;
|
|
2924
2987
|
const sharedObjects = await getSharedObjects(lock.nft_type);
|
|
2925
2988
|
if (lock.nft?.token_id) {
|
|
2926
2989
|
throw new Error(`The short lock ${lockId} must not have any nft`);
|
|
2927
2990
|
}
|
|
2928
|
-
const requiredCoins = BigInt(lock.maker_price) + calculateRoyaltyFee(transferPolicy.rules, 0n);
|
|
2929
2991
|
let listing = null;
|
|
2930
2992
|
if (listingId) {
|
|
2931
2993
|
const res = await gqlChainRequest({
|
|
@@ -2969,51 +3031,66 @@ async function exerciseShortLocks({ walletAddress, transaction, locks }, context
|
|
|
2969
3031
|
kioskOwner: walletAddress,
|
|
2970
3032
|
kiosk: nftIdArg ? nft?.chain_state?.kiosk_id : null,
|
|
2971
3033
|
async runCommands(kioskTx) {
|
|
2972
|
-
|
|
2973
|
-
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::start_confirm_short_lock`,
|
|
2974
|
-
typeArguments: [lock.nft_type],
|
|
2975
|
-
arguments: [
|
|
2976
|
-
tx.object(TRADEPORT_PRICE_LOCK_STORE),
|
|
2977
|
-
tx.object(import_utils4.SUI_CLOCK_OBJECT_ID),
|
|
2978
|
-
tx.pure.id(lock.lock_id),
|
|
2979
|
-
tx.pure.u64(requiredCoins)
|
|
2980
|
-
]
|
|
2981
|
-
});
|
|
3034
|
+
let confirmLockRequest;
|
|
2982
3035
|
if (listing) {
|
|
3036
|
+
const beforeResolveKioskTransferRequest = async (transferRequest) => {
|
|
3037
|
+
const [request] = tx.moveCall({
|
|
3038
|
+
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::start_confirm_short_lock_with_buy_listing`,
|
|
3039
|
+
typeArguments: [lock.nft_type],
|
|
3040
|
+
arguments: [
|
|
3041
|
+
tx.object(TRADEPORT_PRICE_LOCK_STORE),
|
|
3042
|
+
tx.object(import_utils4.SUI_CLOCK_OBJECT_ID),
|
|
3043
|
+
tx.pure.id(lock.lock_id),
|
|
3044
|
+
tx.pure.u64(listing.price),
|
|
3045
|
+
tx.pure.u64(calculateRoyaltyFee(transferPolicy.rules, BigInt(listing.price))),
|
|
3046
|
+
transferRequest
|
|
3047
|
+
]
|
|
3048
|
+
});
|
|
3049
|
+
confirmLockRequest = request;
|
|
3050
|
+
};
|
|
2983
3051
|
await buyListings(
|
|
2984
3052
|
{
|
|
2985
3053
|
listingIds: [listingId],
|
|
2986
3054
|
walletAddress,
|
|
2987
3055
|
tx,
|
|
2988
|
-
kioskTx
|
|
3056
|
+
kioskTx,
|
|
3057
|
+
beforeResolveKioskTransferRequest
|
|
2989
3058
|
},
|
|
2990
3059
|
context
|
|
2991
3060
|
);
|
|
3061
|
+
} else {
|
|
3062
|
+
const [buyListinTransferRequest, request] = tx.moveCall({
|
|
3063
|
+
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::start_confirm_short_lock`,
|
|
3064
|
+
typeArguments: [lock.nft_type],
|
|
3065
|
+
arguments: [
|
|
3066
|
+
tx.object(TRADEPORT_PRICE_LOCK_STORE),
|
|
3067
|
+
tx.object(import_utils4.SUI_CLOCK_OBJECT_ID),
|
|
3068
|
+
tx.pure.id(lock.lock_id),
|
|
3069
|
+
tx.pure.id(nft.token_id),
|
|
3070
|
+
tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk)
|
|
3071
|
+
]
|
|
3072
|
+
});
|
|
3073
|
+
confirmLockRequest = request;
|
|
3074
|
+
await resolveTransferPolicies({
|
|
3075
|
+
tx,
|
|
3076
|
+
kioskTx,
|
|
3077
|
+
nftType: lock.nft_type,
|
|
3078
|
+
price: lock.maker_price.toString(),
|
|
3079
|
+
transferRequest: buyListinTransferRequest,
|
|
3080
|
+
shouldSkipKioskLocking: true
|
|
3081
|
+
});
|
|
2992
3082
|
}
|
|
2993
|
-
|
|
3083
|
+
tx.moveCall({
|
|
2994
3084
|
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::end_confirm_short_lock`,
|
|
2995
3085
|
typeArguments: [lock.nft_type],
|
|
2996
3086
|
arguments: [
|
|
2997
3087
|
tx.object(TRADEPORT_PRICE_LOCK_STORE),
|
|
2998
3088
|
tx.object(TRADEPORT_KIOSK_TRANSFERS_STORE),
|
|
2999
|
-
|
|
3000
|
-
tx.pure.id(nft.token_id),
|
|
3001
|
-
tx.object(TRADEPORT_KIOSK_TRANSFERS_ESCROW_KIOSK),
|
|
3089
|
+
confirmLockRequest,
|
|
3002
3090
|
tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
|
|
3003
|
-
tx.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap)
|
|
3004
|
-
tx.object(transferPolicyId),
|
|
3005
|
-
tx.pure.u64(listing?.price ?? 0n)
|
|
3091
|
+
tx.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap)
|
|
3006
3092
|
]
|
|
3007
3093
|
});
|
|
3008
|
-
await resolveTransferPolicies({
|
|
3009
|
-
tx,
|
|
3010
|
-
kioskTx,
|
|
3011
|
-
nftType: lock.nft_type,
|
|
3012
|
-
price: "0",
|
|
3013
|
-
transferRequest,
|
|
3014
|
-
kioskToLockRuleProve: TRADEPORT_KIOSK_TRANSFERS_ESCROW_KIOSK,
|
|
3015
|
-
shouldSkipKioskLocking: true
|
|
3016
|
-
});
|
|
3017
3094
|
}
|
|
3018
3095
|
});
|
|
3019
3096
|
}
|