@6529-collections/stream-sdk 0.0.0-stage → 0.1.0-bootstrap.0
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 +46 -0
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +413 -2
- package/dist/actions/accounts.d.ts +58 -0
- package/dist/actions/accounts.js +73 -0
- package/dist/actions/content.d.ts +22 -0
- package/dist/actions/content.js +45 -0
- package/dist/actions/curated.d.ts +177 -0
- package/dist/actions/curated.js +279 -0
- package/dist/actions/editions.d.ts +100 -0
- package/dist/actions/editions.js +161 -0
- package/dist/actions/independent.d.ts +149 -0
- package/dist/actions/independent.js +274 -0
- package/dist/actions/money.d.ts +117 -0
- package/dist/actions/money.js +148 -0
- package/dist/actions/record.d.ts +144 -0
- package/dist/actions/record.js +229 -0
- package/dist/actions/sale.d.ts +82 -0
- package/dist/actions/sale.js +113 -0
- package/dist/actions/shared.d.ts +40 -0
- package/dist/actions/shared.js +70 -0
- package/dist/actions/vault.d.ts +58 -0
- package/dist/actions/vault.js +94 -0
- package/dist/constants.d.ts +130 -0
- package/dist/constants.js +65 -0
- package/dist/display.d.ts +31 -0
- package/dist/display.js +28 -0
- package/dist/encoding.d.ts +110 -0
- package/dist/encoding.js +138 -0
- package/dist/errors.d.ts +76 -0
- package/dist/errors.js +66 -0
- package/dist/files/fetch.d.ts +85 -0
- package/dist/files/fetch.js +208 -0
- package/dist/files/verify.d.ts +36 -0
- package/dist/files/verify.js +125 -0
- package/dist/generated/abis/AccessManager.d.ts +1125 -0
- package/dist/generated/abis/AccessManager.js +1471 -0
- package/dist/generated/abis/Accounts.d.ts +1568 -0
- package/dist/generated/abis/Accounts.js +2049 -0
- package/dist/generated/abis/ClaimRouter.d.ts +343 -0
- package/dist/generated/abis/ClaimRouter.js +452 -0
- package/dist/generated/abis/ConsolidationAdapter.d.ts +97 -0
- package/dist/generated/abis/ConsolidationAdapter.js +133 -0
- package/dist/generated/abis/ContentStore.d.ts +812 -0
- package/dist/generated/abis/ContentStore.js +1073 -0
- package/dist/generated/abis/EconomicsResolver.d.ts +586 -0
- package/dist/generated/abis/EconomicsResolver.js +769 -0
- package/dist/generated/abis/Eip712CurationVerifier.d.ts +304 -0
- package/dist/generated/abis/Eip712CurationVerifier.js +406 -0
- package/dist/generated/abis/EnglishAuction.d.ts +1435 -0
- package/dist/generated/abis/EnglishAuction.js +1865 -0
- package/dist/generated/abis/GovernedVault.d.ts +468 -0
- package/dist/generated/abis/GovernedVault.js +617 -0
- package/dist/generated/abis/IndependentEditionAuction.d.ts +2373 -0
- package/dist/generated/abis/IndependentEditionAuction.js +3076 -0
- package/dist/generated/abis/IndependentStream6529.d.ts +1408 -0
- package/dist/generated/abis/IndependentStream6529.js +1834 -0
- package/dist/generated/abis/IndependentStreamDeployer.d.ts +141 -0
- package/dist/generated/abis/IndependentStreamDeployer.js +188 -0
- package/dist/generated/abis/IndependentStreamEditions6529.d.ts +963 -0
- package/dist/generated/abis/IndependentStreamEditions6529.js +1253 -0
- package/dist/generated/abis/IndependentStreamRegistry.d.ts +1351 -0
- package/dist/generated/abis/IndependentStreamRegistry.js +1755 -0
- package/dist/generated/abis/PackageRegistry.d.ts +1205 -0
- package/dist/generated/abis/PackageRegistry.js +1573 -0
- package/dist/generated/abis/RevenueEscrow.d.ts +626 -0
- package/dist/generated/abis/RevenueEscrow.js +820 -0
- package/dist/generated/abis/SaleStarter.d.ts +48 -0
- package/dist/generated/abis/SaleStarter.js +67 -0
- package/dist/generated/abis/SepoliaOpenGate.d.ts +317 -0
- package/dist/generated/abis/SepoliaOpenGate.js +419 -0
- package/dist/generated/abis/SplitLedger.d.ts +1097 -0
- package/dist/generated/abis/SplitLedger.js +1438 -0
- package/dist/generated/abis/StatementLog.d.ts +958 -0
- package/dist/generated/abis/StatementLog.js +1248 -0
- package/dist/generated/abis/Stream6529.d.ts +1490 -0
- package/dist/generated/abis/Stream6529.js +1941 -0
- package/dist/generated/abis/StreamDirectory6529.d.ts +355 -0
- package/dist/generated/abis/StreamDirectory6529.js +468 -0
- package/dist/generated/abis/StreamEditions6529.d.ts +1240 -0
- package/dist/generated/abis/StreamEditions6529.js +1614 -0
- package/dist/generated/abis/StreamTerms.d.ts +312 -0
- package/dist/generated/abis/StreamTerms.js +409 -0
- package/dist/generated/abis/StreamWorkFacts6529.d.ts +810 -0
- package/dist/generated/abis/StreamWorkFacts6529.js +1049 -0
- package/dist/generated/abis/UniformEditionAuction.d.ts +2372 -0
- package/dist/generated/abis/UniformEditionAuction.js +3074 -0
- package/dist/generated/abis/WorkDelivery.d.ts +605 -0
- package/dist/generated/abis/WorkDelivery.js +786 -0
- package/dist/generated/abis/WorkRules.d.ts +1154 -0
- package/dist/generated/abis/WorkRules.js +1501 -0
- package/dist/generated/abis/index.d.ts +28 -0
- package/dist/generated/abis/index.js +31 -0
- package/dist/generated/instances.d.ts +7 -0
- package/dist/generated/instances.js +9 -0
- package/dist/generated/sepoliaR10.d.ts +1391 -0
- package/dist/generated/sepoliaR10.js +1545 -0
- package/dist/hashing/content.d.ts +42 -0
- package/dist/hashing/content.js +54 -0
- package/dist/hashing/ids.d.ts +67 -0
- package/dist/hashing/ids.js +73 -0
- package/dist/hashing/items.d.ts +30 -0
- package/dist/hashing/items.js +44 -0
- package/dist/hashing/packages.d.ts +35 -0
- package/dist/hashing/packages.js +76 -0
- package/dist/hashing/vault.d.ts +17 -0
- package/dist/hashing/vault.js +37 -0
- package/dist/hashing/workState.d.ts +31 -0
- package/dist/hashing/workState.js +37 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +47 -0
- package/dist/instance.d.ts +236 -0
- package/dist/instance.js +99 -0
- package/dist/items.d.ts +85 -0
- package/dist/items.js +144 -0
- package/dist/reads/accounts.d.ts +86 -0
- package/dist/reads/accounts.js +121 -0
- package/dist/reads/chain.d.ts +54 -0
- package/dist/reads/chain.js +133 -0
- package/dist/reads/creation.d.ts +139 -0
- package/dist/reads/creation.js +256 -0
- package/dist/reads/editionSale.d.ts +120 -0
- package/dist/reads/editionSale.js +182 -0
- package/dist/reads/metadata.d.ts +195 -0
- package/dist/reads/metadata.js +191 -0
- package/dist/reads/money.d.ts +51 -0
- package/dist/reads/money.js +68 -0
- package/dist/reads/network.d.ts +137 -0
- package/dist/reads/network.js +157 -0
- package/dist/reads/sale.d.ts +94 -0
- package/dist/reads/sale.js +133 -0
- package/dist/reads/vault.d.ts +47 -0
- package/dist/reads/vault.js +75 -0
- package/dist/reads/work.d.ts +293 -0
- package/dist/reads/work.js +338 -0
- package/dist/reads/workPage.d.ts +197 -0
- package/dist/reads/workPage.js +169 -0
- package/dist/signing/messages.d.ts +679 -0
- package/dist/signing/messages.js +397 -0
- package/dist/testing.d.ts +17 -0
- package/dist/testing.js +18 -0
- package/dist/types.d.ts +167 -0
- package/dist/types.js +14 -0
- package/docs/publishing.md +54 -0
- package/docs/reference.md +335 -0
- package/docs/using-from-a-site.md +175 -0
- package/package.json +93 -4
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { isAddressEqual, parseEventLogs } from "viem";
|
|
3
|
+
import { readContract } from "viem/actions";
|
|
4
|
+
import { CURRENCY_ETH, EDITION_STATUS } from "../constants.js";
|
|
5
|
+
import { FlowError } from "../errors.js";
|
|
6
|
+
import { uniformEditionAuctionAbi } from "../generated/abis/UniformEditionAuction.js";
|
|
7
|
+
import { accountOf, send } from "./shared.js";
|
|
8
|
+
function on(ref) {
|
|
9
|
+
return { address: ref.auction, abi: uniformEditionAuctionAbi };
|
|
10
|
+
}
|
|
11
|
+
/** Refuses an auction address that is not one of the instance's two edition auctions: these actions send ETH to it. */
|
|
12
|
+
function assertAuction(instance, ref) {
|
|
13
|
+
const known = [instance.addresses.editionAuction, instance.addresses.independentEditionAuction];
|
|
14
|
+
if (!known.some((address) => isAddressEqual(address, ref.auction))) {
|
|
15
|
+
throw new FlowError("INVALID_INPUT", `${ref.auction} is not an edition auction of instance ${instance.name}.`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Bids for `quantity` copies at price step `step` of the sale's ladder. The bid pays exactly
|
|
20
|
+
* `stepPrice(step) * quantity`, read from the contract here. Every winner pays the one
|
|
21
|
+
* clearing price in the end; what was paid above it comes back when the bid is claimed.
|
|
22
|
+
*
|
|
23
|
+
* Contract: [`UniformEditionAuction.bid`, `stepPrice`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
|
|
24
|
+
*
|
|
25
|
+
* @returns the transaction, the bid's ID (needed to raise and to claim) and what was paid.
|
|
26
|
+
*/
|
|
27
|
+
export async function bidEdition(clients, instance, args) {
|
|
28
|
+
assertAuction(instance, args);
|
|
29
|
+
if (!Number.isSafeInteger(args.quantity) || args.quantity <= 0) {
|
|
30
|
+
throw new FlowError("INVALID_INPUT", "The quantity is a whole number of at least 1.");
|
|
31
|
+
}
|
|
32
|
+
const price = await readContract(clients.public, { ...on(args), functionName: "stepPrice", args: [args.saleId, BigInt(args.step)] });
|
|
33
|
+
const paid = price * BigInt(args.quantity);
|
|
34
|
+
const sent = await send(clients, instance, {
|
|
35
|
+
...on(args),
|
|
36
|
+
functionName: "bid",
|
|
37
|
+
args: [args.saleId, BigInt(args.step), BigInt(args.quantity)],
|
|
38
|
+
value: paid,
|
|
39
|
+
});
|
|
40
|
+
const account = accountOf(clients);
|
|
41
|
+
const placed = parseEventLogs({ abi: uniformEditionAuctionAbi, logs: sent.receipt.logs, eventName: "BidPlaced" }).find((log) => isAddressEqual(log.address, args.auction) && log.args.saleId === args.saleId && isAddressEqual(log.args.bidder, account));
|
|
42
|
+
if (!placed)
|
|
43
|
+
throw new FlowError("MISSING_EVENT", "The transaction emitted no BidPlaced for this wallet.");
|
|
44
|
+
return { ...sent, bidId: placed.args.bidId, paid };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Moves the wallet's bid up to a higher price step, paying exactly the difference for every
|
|
48
|
+
* unit. A raised bid joins the back of its new step.
|
|
49
|
+
*
|
|
50
|
+
* Contract: [`UniformEditionAuction.raise`, `bidOf`, `stepPrice`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
|
|
51
|
+
*/
|
|
52
|
+
export async function raiseEditionBid(clients, instance, args) {
|
|
53
|
+
assertAuction(instance, args);
|
|
54
|
+
const current = await readContract(clients.public, { ...on(args), functionName: "bidOf", args: [args.saleId, args.bidId] });
|
|
55
|
+
if (args.newStep <= current.step)
|
|
56
|
+
throw new FlowError("INVALID_INPUT", "A bid can only be raised to a higher step.");
|
|
57
|
+
const [from, to] = await Promise.all([
|
|
58
|
+
readContract(clients.public, { ...on(args), functionName: "stepPrice", args: [args.saleId, BigInt(current.step)] }),
|
|
59
|
+
readContract(clients.public, { ...on(args), functionName: "stepPrice", args: [args.saleId, BigInt(args.newStep)] }),
|
|
60
|
+
]);
|
|
61
|
+
const paid = (to - from) * BigInt(current.quantity);
|
|
62
|
+
const sent = await send(clients, instance, {
|
|
63
|
+
...on(args),
|
|
64
|
+
functionName: "raise",
|
|
65
|
+
args: [args.saleId, args.bidId, BigInt(args.newStep)],
|
|
66
|
+
value: paid,
|
|
67
|
+
});
|
|
68
|
+
return { ...sent, paid };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Settles a closed edition sale. Anyone may. Settlement runs in calls of bounded gas, so this
|
|
72
|
+
* sends as many transactions as it takes (at most `maxTransactions`, default 20): the
|
|
73
|
+
* contract is asked for the caller's next slice of the order before each one.
|
|
74
|
+
*
|
|
75
|
+
* It can settle only after the sale closed and its 1/1 was settled or cancelled.
|
|
76
|
+
*
|
|
77
|
+
* Contract: [`UniformEditionAuction.settle`, `settlementOrderFor`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
|
|
78
|
+
*
|
|
79
|
+
* @returns the transactions sent, whether the sale is settled now, and whether it ended void
|
|
80
|
+
* instead (its 1/1 was cancelled: every bidder takes their ETH back with `claimEditionBid`).
|
|
81
|
+
*/
|
|
82
|
+
export async function settleEditionSale(clients, instance, args) {
|
|
83
|
+
assertAuction(instance, args);
|
|
84
|
+
const account = accountOf(clients);
|
|
85
|
+
const transactions = [];
|
|
86
|
+
const state = async () => {
|
|
87
|
+
const sale = await readContract(clients.public, { ...on(args), functionName: "auction", args: [args.saleId] });
|
|
88
|
+
return { settled: sale.status === EDITION_STATUS.SETTLED, voided: sale.status === EDITION_STATUS.VOID };
|
|
89
|
+
};
|
|
90
|
+
for (let round = 0; round < (args.maxTransactions ?? 20); round++) {
|
|
91
|
+
const now = await state();
|
|
92
|
+
if (now.settled || now.voided)
|
|
93
|
+
return { ...now, transactions };
|
|
94
|
+
// The caller's own remaining slice. The contract keeps each settler's progress and refuses
|
|
95
|
+
// an order that starts before it, so the whole order is right only for a first call;
|
|
96
|
+
// this answer is right in every state, including when an earlier run stopped half way.
|
|
97
|
+
const order = await readContract(clients.public, { ...on(args), functionName: "settlementOrderFor", args: [args.saleId, account] });
|
|
98
|
+
transactions.push(await send(clients, instance, { ...on(args), functionName: "settle", args: [args.saleId, order] }));
|
|
99
|
+
}
|
|
100
|
+
return { ...(await state()), transactions };
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Claims the wallet's bid after settlement: the copies it won are minted to `to` (default:
|
|
104
|
+
* the wallet itself), and the ETH it did not spend is paid back.
|
|
105
|
+
*
|
|
106
|
+
* Contract: [`UniformEditionAuction.claimBid`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
|
|
107
|
+
*
|
|
108
|
+
* @returns the transaction, the copies won and the ETH returned.
|
|
109
|
+
*/
|
|
110
|
+
export async function claimEditionBid(clients, instance, args) {
|
|
111
|
+
assertAuction(instance, args);
|
|
112
|
+
const sent = await send(clients, instance, {
|
|
113
|
+
...on(args),
|
|
114
|
+
functionName: "claimBid",
|
|
115
|
+
args: [args.saleId, args.bidId, args.to ?? accountOf(clients)],
|
|
116
|
+
});
|
|
117
|
+
return { ...sent, ...claimedOf(sent, args) };
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Claims someone else's bid for them. Anyone may: the copies go to the bidder, and the refund
|
|
121
|
+
* is credited to the bidder, who withdraws it with `claimEditionCredit`.
|
|
122
|
+
*
|
|
123
|
+
* Contract: [`UniformEditionAuction.claimBidFor`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
|
|
124
|
+
*/
|
|
125
|
+
export async function claimEditionBidFor(clients, instance, args) {
|
|
126
|
+
assertAuction(instance, args);
|
|
127
|
+
const sent = await send(clients, instance, { ...on(args), functionName: "claimBidFor", args: [args.saleId, args.bidId] });
|
|
128
|
+
return { ...sent, ...claimedOf(sent, args) };
|
|
129
|
+
}
|
|
130
|
+
function claimedOf(sent, args) {
|
|
131
|
+
const claimed = parseEventLogs({ abi: uniformEditionAuctionAbi, logs: sent.receipt.logs, eventName: "BidClaimed" }).find((log) => isAddressEqual(log.address, args.auction) && log.args.saleId === args.saleId && log.args.bidId === args.bidId);
|
|
132
|
+
if (!claimed)
|
|
133
|
+
throw new FlowError("MISSING_EVENT", "The transaction emitted no BidClaimed for this bid.");
|
|
134
|
+
return { unitsWon: claimed.args.unitsWon, refund: claimed.args.refund };
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Withdraws the ETH credited to the connected wallet on an edition auction (refunds that were
|
|
138
|
+
* credited instead of paid), to `to` (default: the wallet itself).
|
|
139
|
+
*
|
|
140
|
+
* Contract: [`UniformEditionAuction.claim`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol)
|
|
141
|
+
* with the ETH currency (the zero address).
|
|
142
|
+
*/
|
|
143
|
+
export async function claimEditionCredit(clients, instance, args) {
|
|
144
|
+
assertAuction(instance, args);
|
|
145
|
+
return send(clients, instance, {
|
|
146
|
+
address: args.auction,
|
|
147
|
+
abi: uniformEditionAuctionAbi,
|
|
148
|
+
functionName: "claim",
|
|
149
|
+
args: [CURRENCY_ETH, args.to ?? accountOf(clients)],
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Voids an edition sale that can no longer settle (`readEditionSale(...).abandonable`), so
|
|
154
|
+
* every bidder can take their ETH back. Anyone may.
|
|
155
|
+
*
|
|
156
|
+
* Contract: [`UniformEditionAuction.abandon`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
|
|
157
|
+
*/
|
|
158
|
+
export async function abandonEditionSale(clients, instance, args) {
|
|
159
|
+
assertAuction(instance, args);
|
|
160
|
+
return send(clients, instance, { ...on(args), functionName: "abandon", args: [args.saleId] });
|
|
161
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { type Address, type Hex } from "viem";
|
|
2
|
+
import { type StreamInstance } from "../instance.js";
|
|
3
|
+
import type { MediaFile, PackageItem } from "../types.js";
|
|
4
|
+
import { type StartedSale } from "./curated.js";
|
|
5
|
+
import { type Sent, type StreamClients } from "./shared.js";
|
|
6
|
+
/**
|
|
7
|
+
* Deploys an artist's own 1/1 contract (Independent Stream) from the approved template. The
|
|
8
|
+
* contract is the artist's for good: every work minted there names this artist. It mints
|
|
9
|
+
* nothing until it is listed (`listIndependentContract`).
|
|
10
|
+
*
|
|
11
|
+
* The contract is bound to one artist ID for good. By default that is the ID of the account
|
|
12
|
+
* the connected wallet is the root of, or the ID its new account will get. A wallet that acts
|
|
13
|
+
* for an account only through consolidation MUST pass that account's `artistId`: the chain has
|
|
14
|
+
* no lookup from such a wallet to its account, and the default would bind the contract to a
|
|
15
|
+
* new one-wallet account instead. A given `artistId` is checked: the wallet must act for it.
|
|
16
|
+
*
|
|
17
|
+
* `owner` is the ERC-173 owner marketplaces let edit the collection page; it has no power
|
|
18
|
+
* over works. Default: the connected wallet. The deployment uses a lot of gas (about 23
|
|
19
|
+
* million on Sepolia).
|
|
20
|
+
*
|
|
21
|
+
* Contract: [`IndependentStreamDeployer.deploy`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamDeployer.sol)
|
|
22
|
+
* with `encodeIndependent721Config`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function deployIndependentContract(clients: StreamClients, instance: StreamInstance, args: {
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly symbol: string;
|
|
27
|
+
readonly artistId?: bigint;
|
|
28
|
+
readonly owner?: Address;
|
|
29
|
+
readonly salt?: Hex;
|
|
30
|
+
}): Promise<Sent & {
|
|
31
|
+
token: Address;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Deploys the editions contract that partners an artist's 1/1 contract `master`. It is needed
|
|
35
|
+
* only to sell editions of the artist's works, and must be listed too.
|
|
36
|
+
*
|
|
37
|
+
* Contract: [`IndependentStreamDeployer.deploy`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamDeployer.sol)
|
|
38
|
+
* with `encodeIndependentEditionsConfig`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function deployIndependentEditions(clients: StreamClients, instance: StreamInstance, args: {
|
|
41
|
+
readonly name: string;
|
|
42
|
+
readonly symbol: string;
|
|
43
|
+
readonly master: Address;
|
|
44
|
+
/** As for `deployIndependentContract`. Default: the artist ID of `master`. */
|
|
45
|
+
readonly artistId?: bigint;
|
|
46
|
+
readonly owner?: Address;
|
|
47
|
+
readonly salt?: Hex;
|
|
48
|
+
}): Promise<Sent & {
|
|
49
|
+
token: Address;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Lists an artist's contract in the Independent Stream module, so sales can mint into it. The
|
|
53
|
+
* wallet signs a consent to the listing, then sends `register`. A contract is listed once and
|
|
54
|
+
* never leaves the directory (the network can delist it, which stops its sales).
|
|
55
|
+
*
|
|
56
|
+
* Whose account it is comes from the contract: its `artistId()`. If no account with that ID
|
|
57
|
+
* exists yet, the listing creates it, which needs a registration signed by the wallet whose
|
|
58
|
+
* number the ID is, and `profile`: the fields the new account stores for good. Otherwise the
|
|
59
|
+
* account's stored profile is used, and any wallet of the account may sign the consent.
|
|
60
|
+
*
|
|
61
|
+
* The listing subject the wallet consents to is computed here from the plan (`listingSubject`),
|
|
62
|
+
* not taken from an RPC. Signatures expire `lifetimeSeconds` (default 24 hours) after the
|
|
63
|
+
* chain's latest block.
|
|
64
|
+
*
|
|
65
|
+
* Contract: [`IndependentStreamRegistry.register`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamRegistry.sol);
|
|
66
|
+
* messages `ArtistRegistration` and `Consent` in the accounts domain.
|
|
67
|
+
*
|
|
68
|
+
* @returns the transaction, or null when the contract was listed already (also when it was
|
|
69
|
+
* delisted since: read `readEditionVenue` or the registry's `listingOf` for its status).
|
|
70
|
+
*/
|
|
71
|
+
export declare function listIndependentContract(clients: StreamClients, instance: StreamInstance, args: {
|
|
72
|
+
readonly token: Address;
|
|
73
|
+
/**
|
|
74
|
+
* The network's share the artist was shown and agreed to (`readListingPlan(...).feeShare`,
|
|
75
|
+
* out of 100,000). The consent the wallet signs commits to the share, but shows only a
|
|
76
|
+
* hash; if the share on chain is no longer this one, nothing is signed.
|
|
77
|
+
*/
|
|
78
|
+
readonly expectedFeeShare: number;
|
|
79
|
+
readonly profile?: {
|
|
80
|
+
readonly profileId: Hex;
|
|
81
|
+
readonly profileDocHash: Hex;
|
|
82
|
+
};
|
|
83
|
+
readonly lifetimeSeconds?: number;
|
|
84
|
+
}): Promise<Sent | null>;
|
|
85
|
+
/**
|
|
86
|
+
* The artist approves one item for one mint into their own 1/1 contract, with the royalty
|
|
87
|
+
* rate its work gets (out of 100,000). Any wallet of the contract's artist may send it. The
|
|
88
|
+
* approval can be changed until the item is minted. Nothing is sent when the item is approved
|
|
89
|
+
* at this rate already.
|
|
90
|
+
*
|
|
91
|
+
* Contract: [`IndependentStreamRegistry.approveItem`, `itemOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamRegistry.sol).
|
|
92
|
+
*
|
|
93
|
+
* @throws FlowError `ITEM_NOT_APPROVED` when the item was minted already.
|
|
94
|
+
*/
|
|
95
|
+
export declare function approveIndependentItem(clients: StreamClients, instance: StreamInstance, args: {
|
|
96
|
+
readonly token: Address;
|
|
97
|
+
readonly item: PackageItem;
|
|
98
|
+
readonly royaltyRate: number;
|
|
99
|
+
}): Promise<Sent | null>;
|
|
100
|
+
/**
|
|
101
|
+
* A collaborator consents to an Independent Stream item at its royalty rate. The result is
|
|
102
|
+
* one entry of `consents` for `startIndependentSale`. The consent holds until it is used.
|
|
103
|
+
*
|
|
104
|
+
* The item hash and the consent subject are computed here.
|
|
105
|
+
*
|
|
106
|
+
* Contract: message `Consent` with subject `token` and what `independentConsent(itemHash, royaltyRate)`,
|
|
107
|
+
* checked by [`Accounts.requireConsent`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/identity/Accounts.sol)
|
|
108
|
+
* when the item is minted.
|
|
109
|
+
*/
|
|
110
|
+
export declare function signIndependentConsent(clients: StreamClients, instance: StreamInstance, args: {
|
|
111
|
+
readonly token: Address;
|
|
112
|
+
readonly item: PackageItem;
|
|
113
|
+
readonly royaltyRate: number;
|
|
114
|
+
}): Promise<Hex>;
|
|
115
|
+
/**
|
|
116
|
+
* Starts the sale of an item the artist approved for their own contract: the work is minted
|
|
117
|
+
* into the English auction. Anyone may send it. With `firstBid` (wei) the sender places the
|
|
118
|
+
* first bid in the same transaction.
|
|
119
|
+
*
|
|
120
|
+
* If the item is minted already nothing is sent; the check compares item hashes, not only the
|
|
121
|
+
* content (`readMintedToken`). The record is opened afterwards with `openRecord`.
|
|
122
|
+
*
|
|
123
|
+
* Contract: [`EnglishAuction.start`, `startWithBid`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol)
|
|
124
|
+
* with `encodeIndependentMint`.
|
|
125
|
+
*/
|
|
126
|
+
export declare function startIndependentSale(clients: StreamClients, instance: StreamInstance, args: {
|
|
127
|
+
readonly token: Address;
|
|
128
|
+
readonly item: PackageItem;
|
|
129
|
+
readonly media: readonly MediaFile[];
|
|
130
|
+
/** One per collaborator, in party order (`signIndependentConsent`). */
|
|
131
|
+
readonly consents?: readonly Hex[];
|
|
132
|
+
readonly firstBid?: bigint;
|
|
133
|
+
}): Promise<StartedSale>;
|
|
134
|
+
/**
|
|
135
|
+
* Opens the edition sale of an Independent Stream edition master, beside its 1/1 sale. Anyone
|
|
136
|
+
* may send it, from the start of the 1/1 until 15 minutes after the 1/1 ends. Nothing is sent
|
|
137
|
+
* when it is open already.
|
|
138
|
+
*
|
|
139
|
+
* Contract: [`IndependentEditionAuction.open`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentEditionAuction.sol)
|
|
140
|
+
* with `encodeIndependentEditionOpen(item)`.
|
|
141
|
+
*/
|
|
142
|
+
export declare function openIndependentEditionSale(clients: StreamClients, instance: StreamInstance, args: {
|
|
143
|
+
readonly editions: Address;
|
|
144
|
+
readonly tokenId: bigint;
|
|
145
|
+
readonly item: PackageItem;
|
|
146
|
+
}): Promise<{
|
|
147
|
+
saleId: bigint;
|
|
148
|
+
sent: Sent | null;
|
|
149
|
+
}>;
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { bytesToHex, isAddressEqual, parseEventLogs, zeroAddress } from "viem";
|
|
3
|
+
import { readContract } from "viem/actions";
|
|
4
|
+
import { LISTING_STATUS } from "../constants.js";
|
|
5
|
+
import { encodeIndependent721Config, encodeIndependentEditionOpen, encodeIndependentEditionsConfig, encodeIndependentMint } from "../encoding.js";
|
|
6
|
+
import { FlowError } from "../errors.js";
|
|
7
|
+
import { englishAuctionAbi } from "../generated/abis/EnglishAuction.js";
|
|
8
|
+
import { accountsAbi } from "../generated/abis/Accounts.js";
|
|
9
|
+
import { independentStream6529Abi } from "../generated/abis/IndependentStream6529.js";
|
|
10
|
+
import { independentStreamDeployerAbi } from "../generated/abis/IndependentStreamDeployer.js";
|
|
11
|
+
import { independentStreamRegistryAbi } from "../generated/abis/IndependentStreamRegistry.js";
|
|
12
|
+
import { uniformEditionAuctionAbi } from "../generated/abis/UniformEditionAuction.js";
|
|
13
|
+
import { artistIdAddress, independentConsent, listingSubject, saleId as saleIdOf } from "../hashing/ids.js";
|
|
14
|
+
import { itemHash, mediaHash } from "../hashing/items.js";
|
|
15
|
+
import {} from "../instance.js";
|
|
16
|
+
import { readArtistId, readIsWallet } from "../reads/accounts.js";
|
|
17
|
+
import { chainDeadline, orOnRevert } from "../reads/chain.js";
|
|
18
|
+
import { artistRegistrationTypedData, consentTypedData, signingDomains, walletProof } from "../signing/messages.js";
|
|
19
|
+
import { itemProblems } from "../items.js";
|
|
20
|
+
import { readListingPlan, readMintedToken } from "../reads/creation.js";
|
|
21
|
+
import { startedTokenId } from "./curated.js";
|
|
22
|
+
import { assertReady, send, sign } from "./shared.js";
|
|
23
|
+
/** Refuses an item that breaks a rule that needs no chain to check, naming the rule, before anything is signed or sent. */
|
|
24
|
+
function assertItem(item) {
|
|
25
|
+
const problems = itemProblems(item, { independent: true });
|
|
26
|
+
if (problems.length > 0) {
|
|
27
|
+
throw new FlowError("INVALID_INPUT", `The item breaks ${problems.length === 1 ? "a rule" : "rules"}: ${problems.map((problem) => `${problem.message} (${problem.rule})`).join(" ")}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** A random 32-byte salt for a deployment. */
|
|
31
|
+
function randomSalt() {
|
|
32
|
+
return bytesToHex(crypto.getRandomValues(new Uint8Array(32)));
|
|
33
|
+
}
|
|
34
|
+
async function deploy(clients, instance, deployer, salt, config) {
|
|
35
|
+
const caller = await assertReady(clients, instance);
|
|
36
|
+
const sent = await send(clients, instance, { address: deployer, abi: independentStreamDeployerAbi, functionName: "deploy", args: [salt, config] });
|
|
37
|
+
const deployed = parseEventLogs({ abi: independentStreamDeployerAbi, logs: sent.receipt.logs, eventName: "Deployed" }).find((log) => isAddressEqual(log.address, deployer) && isAddressEqual(log.args.caller, caller));
|
|
38
|
+
if (!deployed)
|
|
39
|
+
throw new FlowError("MISSING_EVENT", "The transaction emitted no Deployed event from the deployer.");
|
|
40
|
+
return { ...sent, token: deployed.args.token };
|
|
41
|
+
}
|
|
42
|
+
/** The artist ID a deployment binds its contract to: the one given (checked), or the wallet's own. */
|
|
43
|
+
async function deployArtistId(clients, instance, account, given) {
|
|
44
|
+
const own = await readArtistId(clients.public, instance, account);
|
|
45
|
+
if (given === undefined || given === own.artistId)
|
|
46
|
+
return own.artistId;
|
|
47
|
+
// `isWallet` reverts for an account that does not exist.
|
|
48
|
+
if (!(await orOnRevert(readIsWallet(clients.public, instance, given, account), false))) {
|
|
49
|
+
throw new FlowError("INVALID_INPUT", `Wallet ${account} does not act for artist ${given}.`);
|
|
50
|
+
}
|
|
51
|
+
return given;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Deploys an artist's own 1/1 contract (Independent Stream) from the approved template. The
|
|
55
|
+
* contract is the artist's for good: every work minted there names this artist. It mints
|
|
56
|
+
* nothing until it is listed (`listIndependentContract`).
|
|
57
|
+
*
|
|
58
|
+
* The contract is bound to one artist ID for good. By default that is the ID of the account
|
|
59
|
+
* the connected wallet is the root of, or the ID its new account will get. A wallet that acts
|
|
60
|
+
* for an account only through consolidation MUST pass that account's `artistId`: the chain has
|
|
61
|
+
* no lookup from such a wallet to its account, and the default would bind the contract to a
|
|
62
|
+
* new one-wallet account instead. A given `artistId` is checked: the wallet must act for it.
|
|
63
|
+
*
|
|
64
|
+
* `owner` is the ERC-173 owner marketplaces let edit the collection page; it has no power
|
|
65
|
+
* over works. Default: the connected wallet. The deployment uses a lot of gas (about 23
|
|
66
|
+
* million on Sepolia).
|
|
67
|
+
*
|
|
68
|
+
* Contract: [`IndependentStreamDeployer.deploy`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamDeployer.sol)
|
|
69
|
+
* with `encodeIndependent721Config`.
|
|
70
|
+
*/
|
|
71
|
+
export async function deployIndependentContract(clients, instance, args) {
|
|
72
|
+
const account = await assertReady(clients, instance);
|
|
73
|
+
const artistId = await deployArtistId(clients, instance, account, args.artistId);
|
|
74
|
+
const config = encodeIndependent721Config({
|
|
75
|
+
name: args.name,
|
|
76
|
+
symbol: args.symbol,
|
|
77
|
+
workFacts: instance.addresses.workFacts,
|
|
78
|
+
streamDirectory: instance.addresses.streamDirectory,
|
|
79
|
+
artistId,
|
|
80
|
+
owner: args.owner ?? account,
|
|
81
|
+
renderer: instance.addresses.renderer,
|
|
82
|
+
});
|
|
83
|
+
return deploy(clients, instance, instance.addresses.independent721Deployer, args.salt ?? randomSalt(), config);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Deploys the editions contract that partners an artist's 1/1 contract `master`. It is needed
|
|
87
|
+
* only to sell editions of the artist's works, and must be listed too.
|
|
88
|
+
*
|
|
89
|
+
* Contract: [`IndependentStreamDeployer.deploy`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamDeployer.sol)
|
|
90
|
+
* with `encodeIndependentEditionsConfig`.
|
|
91
|
+
*/
|
|
92
|
+
export async function deployIndependentEditions(clients, instance, args) {
|
|
93
|
+
const account = await assertReady(clients, instance);
|
|
94
|
+
const masterArtistId = await readContract(clients.public, { address: args.master, abi: independentStream6529Abi, functionName: "artistId" });
|
|
95
|
+
const artistId = await deployArtistId(clients, instance, account, args.artistId ?? masterArtistId);
|
|
96
|
+
const config = encodeIndependentEditionsConfig({
|
|
97
|
+
name: args.name,
|
|
98
|
+
symbol: args.symbol,
|
|
99
|
+
master: args.master,
|
|
100
|
+
streamDirectory: instance.addresses.streamDirectory,
|
|
101
|
+
artistId,
|
|
102
|
+
owner: args.owner ?? account,
|
|
103
|
+
});
|
|
104
|
+
return deploy(clients, instance, instance.addresses.independentEditionsDeployer, args.salt ?? randomSalt(), config);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Lists an artist's contract in the Independent Stream module, so sales can mint into it. The
|
|
108
|
+
* wallet signs a consent to the listing, then sends `register`. A contract is listed once and
|
|
109
|
+
* never leaves the directory (the network can delist it, which stops its sales).
|
|
110
|
+
*
|
|
111
|
+
* Whose account it is comes from the contract: its `artistId()`. If no account with that ID
|
|
112
|
+
* exists yet, the listing creates it, which needs a registration signed by the wallet whose
|
|
113
|
+
* number the ID is, and `profile`: the fields the new account stores for good. Otherwise the
|
|
114
|
+
* account's stored profile is used, and any wallet of the account may sign the consent.
|
|
115
|
+
*
|
|
116
|
+
* The listing subject the wallet consents to is computed here from the plan (`listingSubject`),
|
|
117
|
+
* not taken from an RPC. Signatures expire `lifetimeSeconds` (default 24 hours) after the
|
|
118
|
+
* chain's latest block.
|
|
119
|
+
*
|
|
120
|
+
* Contract: [`IndependentStreamRegistry.register`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamRegistry.sol);
|
|
121
|
+
* messages `ArtistRegistration` and `Consent` in the accounts domain.
|
|
122
|
+
*
|
|
123
|
+
* @returns the transaction, or null when the contract was listed already (also when it was
|
|
124
|
+
* delisted since: read `readEditionVenue` or the registry's `listingOf` for its status).
|
|
125
|
+
*/
|
|
126
|
+
export async function listIndependentContract(clients, instance, args) {
|
|
127
|
+
const account = await assertReady(clients, instance);
|
|
128
|
+
const registry = { address: instance.addresses.independentRegistry, abi: independentStreamRegistryAbi };
|
|
129
|
+
const listing = await readContract(clients.public, { ...registry, functionName: "listingOf", args: [args.token] });
|
|
130
|
+
if (listing.status !== LISTING_STATUS.NONE)
|
|
131
|
+
return null;
|
|
132
|
+
const plan = await readListingPlan(clients.public, instance, args.token);
|
|
133
|
+
if (plan.feeShare !== args.expectedFeeShare) {
|
|
134
|
+
throw new FlowError("MISMATCH", `The network's share for a new listing is ${plan.feeShare} of 100,000 now, not the ${args.expectedFeeShare} that was agreed to.`);
|
|
135
|
+
}
|
|
136
|
+
// The registry creates the account when the address whose number the token's artist ID is
|
|
137
|
+
// has no account with that ID (`_identify`); the registration is that address's signature.
|
|
138
|
+
const accounts = { address: instance.addresses.accounts, abi: accountsAbi };
|
|
139
|
+
const artistId = await readContract(clients.public, { address: args.token, abi: independentStream6529Abi, functionName: "artistId" });
|
|
140
|
+
const root = artistIdAddress(artistId);
|
|
141
|
+
const exists = (await readContract(clients.public, { ...accounts, functionName: "artistIdOf", args: [root] })) === artistId;
|
|
142
|
+
let profile;
|
|
143
|
+
if (exists) {
|
|
144
|
+
const [identity] = await readContract(clients.public, { ...accounts, functionName: "artist", args: [artistId] });
|
|
145
|
+
profile = { profileId: identity.profileId, profileDocHash: identity.profileDocHash };
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
if (!isAddressEqual(account, root)) {
|
|
149
|
+
throw new FlowError("INVALID_INPUT", `Artist ${artistId} has no account yet, and only ${root} can sign the registration that creates it.`);
|
|
150
|
+
}
|
|
151
|
+
profile = args.profile;
|
|
152
|
+
}
|
|
153
|
+
if (!profile) {
|
|
154
|
+
throw new FlowError("INVALID_INPUT", "This artist has no account yet: pass the profile fields its registration will store.");
|
|
155
|
+
}
|
|
156
|
+
const deadline = await chainDeadline(clients.public, args.lifetimeSeconds ?? 86_400);
|
|
157
|
+
const domains = signingDomains(instance);
|
|
158
|
+
const registration = exists ? "0x" : await sign(clients, artistRegistrationTypedData(domains.accounts, { account, ...profile, deadline }));
|
|
159
|
+
const what = listingSubject(instance.protocol, { token: plan.token, form: plan.form, partner: plan.partner, feeShare: plan.feeShare, deadline });
|
|
160
|
+
const consent = await sign(clients, consentTypedData(domains.accounts, { subject: instance.addresses.independentRegistry, what }));
|
|
161
|
+
return send(clients, instance, {
|
|
162
|
+
...registry,
|
|
163
|
+
functionName: "register",
|
|
164
|
+
args: [
|
|
165
|
+
args.token,
|
|
166
|
+
{
|
|
167
|
+
deployer: plan.deployer,
|
|
168
|
+
profileId: profile.profileId,
|
|
169
|
+
profileDocHash: profile.profileDocHash,
|
|
170
|
+
deadline,
|
|
171
|
+
registration,
|
|
172
|
+
consent: walletProof(account, consent),
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* The artist approves one item for one mint into their own 1/1 contract, with the royalty
|
|
179
|
+
* rate its work gets (out of 100,000). Any wallet of the contract's artist may send it. The
|
|
180
|
+
* approval can be changed until the item is minted. Nothing is sent when the item is approved
|
|
181
|
+
* at this rate already.
|
|
182
|
+
*
|
|
183
|
+
* Contract: [`IndependentStreamRegistry.approveItem`, `itemOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamRegistry.sol).
|
|
184
|
+
*
|
|
185
|
+
* @throws FlowError `ITEM_NOT_APPROVED` when the item was minted already.
|
|
186
|
+
*/
|
|
187
|
+
export async function approveIndependentItem(clients, instance, args) {
|
|
188
|
+
await assertReady(clients, instance);
|
|
189
|
+
assertItem(args.item);
|
|
190
|
+
const registry = { address: instance.addresses.independentRegistry, abi: independentStreamRegistryAbi };
|
|
191
|
+
const hash = itemHash(instance.protocol, args.item);
|
|
192
|
+
const current = await readContract(clients.public, { ...registry, functionName: "itemOf", args: [args.token, hash] });
|
|
193
|
+
if (current.used)
|
|
194
|
+
throw new FlowError("ITEM_NOT_APPROVED", "This item was minted already: an item mints once.");
|
|
195
|
+
if (current.approved && current.royaltyRate === args.royaltyRate)
|
|
196
|
+
return null;
|
|
197
|
+
return send(clients, instance, { ...registry, functionName: "approveItem", args: [args.token, hash, args.royaltyRate] });
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* A collaborator consents to an Independent Stream item at its royalty rate. The result is
|
|
201
|
+
* one entry of `consents` for `startIndependentSale`. The consent holds until it is used.
|
|
202
|
+
*
|
|
203
|
+
* The item hash and the consent subject are computed here.
|
|
204
|
+
*
|
|
205
|
+
* Contract: message `Consent` with subject `token` and what `independentConsent(itemHash, royaltyRate)`,
|
|
206
|
+
* checked by [`Accounts.requireConsent`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/identity/Accounts.sol)
|
|
207
|
+
* when the item is minted.
|
|
208
|
+
*/
|
|
209
|
+
export async function signIndependentConsent(clients, instance, args) {
|
|
210
|
+
const account = await assertReady(clients, instance);
|
|
211
|
+
assertItem(args.item);
|
|
212
|
+
// The collaborator consents to what the artist approved: the same item at the same rate.
|
|
213
|
+
const approval = await readContract(clients.public, {
|
|
214
|
+
address: instance.addresses.independentRegistry,
|
|
215
|
+
abi: independentStreamRegistryAbi,
|
|
216
|
+
functionName: "itemOf",
|
|
217
|
+
args: [args.token, itemHash(instance.protocol, args.item)],
|
|
218
|
+
});
|
|
219
|
+
if (!approval.approved || approval.used || approval.royaltyRate !== args.royaltyRate) {
|
|
220
|
+
throw new FlowError("ITEM_NOT_APPROVED", "The artist has not approved this item at this royalty rate (or it was minted already).");
|
|
221
|
+
}
|
|
222
|
+
const what = independentConsent(instance.protocol, itemHash(instance.protocol, args.item), args.royaltyRate);
|
|
223
|
+
const signature = await sign(clients, consentTypedData(signingDomains(instance).accounts, { subject: args.token, what }));
|
|
224
|
+
return walletProof(account, signature);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Starts the sale of an item the artist approved for their own contract: the work is minted
|
|
228
|
+
* into the English auction. Anyone may send it. With `firstBid` (wei) the sender places the
|
|
229
|
+
* first bid in the same transaction.
|
|
230
|
+
*
|
|
231
|
+
* If the item is minted already nothing is sent; the check compares item hashes, not only the
|
|
232
|
+
* content (`readMintedToken`). The record is opened afterwards with `openRecord`.
|
|
233
|
+
*
|
|
234
|
+
* Contract: [`EnglishAuction.start`, `startWithBid`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol)
|
|
235
|
+
* with `encodeIndependentMint`.
|
|
236
|
+
*/
|
|
237
|
+
export async function startIndependentSale(clients, instance, args) {
|
|
238
|
+
await assertReady(clients, instance);
|
|
239
|
+
if (mediaHash(instance.protocol, args.media) !== args.item.mediaHash) {
|
|
240
|
+
throw new FlowError("INVALID_INPUT", "The media list does not hash to the item's mediaHash.");
|
|
241
|
+
}
|
|
242
|
+
const minted = await readMintedToken(clients.public, instance, args.token, args.item);
|
|
243
|
+
if (minted !== null)
|
|
244
|
+
return { tokenId: minted, saleId: saleIdOf(args.token, minted), sent: null };
|
|
245
|
+
const request = encodeIndependentMint({ item: args.item, media: args.media, consents: args.consents ?? [] });
|
|
246
|
+
const auction = { address: instance.addresses.englishAuction, abi: englishAuctionAbi };
|
|
247
|
+
const sent = args.firstBid === undefined
|
|
248
|
+
? await send(clients, instance, { ...auction, functionName: "start", args: [args.token, request] })
|
|
249
|
+
: await send(clients, instance, { ...auction, functionName: "startWithBid", args: [args.token, request, zeroAddress], value: args.firstBid });
|
|
250
|
+
const tokenId = startedTokenId(sent, instance, args.token);
|
|
251
|
+
return { tokenId, saleId: saleIdOf(args.token, tokenId), sent };
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Opens the edition sale of an Independent Stream edition master, beside its 1/1 sale. Anyone
|
|
255
|
+
* may send it, from the start of the 1/1 until 15 minutes after the 1/1 ends. Nothing is sent
|
|
256
|
+
* when it is open already.
|
|
257
|
+
*
|
|
258
|
+
* Contract: [`IndependentEditionAuction.open`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentEditionAuction.sol)
|
|
259
|
+
* with `encodeIndependentEditionOpen(item)`.
|
|
260
|
+
*/
|
|
261
|
+
export async function openIndependentEditionSale(clients, instance, args) {
|
|
262
|
+
await assertReady(clients, instance);
|
|
263
|
+
const auction = { address: instance.addresses.independentEditionAuction, abi: uniformEditionAuctionAbi };
|
|
264
|
+
const editionSaleId = saleIdOf(args.editions, args.tokenId);
|
|
265
|
+
const existing = await orOnRevert(readContract(clients.public, { ...auction, functionName: "auction", args: [editionSaleId] }), null);
|
|
266
|
+
if (existing && existing.status !== 0)
|
|
267
|
+
return { saleId: editionSaleId, sent: null };
|
|
268
|
+
const sent = await send(clients, instance, {
|
|
269
|
+
...auction,
|
|
270
|
+
functionName: "open",
|
|
271
|
+
args: [args.editions, args.tokenId, encodeIndependentEditionOpen(args.item)],
|
|
272
|
+
});
|
|
273
|
+
return { saleId: editionSaleId, sent };
|
|
274
|
+
}
|