@continuumdao/ctm-mpc-defi 0.2.49 → 0.2.51
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/agent/catalog.cjs +1344 -22
- package/dist/agent/catalog.cjs.map +1 -1
- package/dist/agent/catalog.d.ts +1528 -9
- package/dist/agent/catalog.js +1316 -23
- package/dist/agent/catalog.js.map +1 -1
- package/dist/agent/skills/continuum-dao/SKILL.md +2 -0
- package/dist/agent/skills/continuum-dao-marketplace/SKILL.md +58 -0
- package/dist/agent/skills/hyperliquidOutcome/SKILL.md +47 -0
- package/dist/agent/skills/trueo/SKILL.md +64 -0
- package/dist/core/index.cjs +3 -1
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +3 -1
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/protocols/evm/aerodrome/index.cjs.map +1 -1
- package/dist/protocols/evm/aerodrome/index.js.map +1 -1
- package/dist/protocols/evm/continuum-dao/index.cjs +2274 -59
- package/dist/protocols/evm/continuum-dao/index.cjs.map +1 -1
- package/dist/protocols/evm/continuum-dao/index.d.ts +690 -2
- package/dist/protocols/evm/continuum-dao/index.js +2218 -61
- package/dist/protocols/evm/continuum-dao/index.js.map +1 -1
- package/dist/protocols/evm/hyperliquidOutcome/index.cjs +1294 -0
- package/dist/protocols/evm/hyperliquidOutcome/index.cjs.map +1 -0
- package/dist/protocols/evm/hyperliquidOutcome/index.d.ts +465 -0
- package/dist/protocols/evm/hyperliquidOutcome/index.js +1247 -0
- package/dist/protocols/evm/hyperliquidOutcome/index.js.map +1 -0
- package/dist/protocols/evm/pendle/index.cjs +3 -1
- package/dist/protocols/evm/pendle/index.cjs.map +1 -1
- package/dist/protocols/evm/pendle/index.js +3 -1
- package/dist/protocols/evm/pendle/index.js.map +1 -1
- package/dist/protocols/evm/trueo/index.cjs +2868 -0
- package/dist/protocols/evm/trueo/index.cjs.map +1 -0
- package/dist/protocols/evm/trueo/index.d.ts +1295 -0
- package/dist/protocols/evm/trueo/index.js +2725 -0
- package/dist/protocols/evm/trueo/index.js.map +1 -0
- package/package.json +11 -1
|
@@ -40,19 +40,19 @@ var init_chainIdParse = __esm({
|
|
|
40
40
|
"src/chains/evm/chainIdParse.ts"() {
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
|
-
function isContinuumDaoCommitteeProposer(
|
|
44
|
-
if (!
|
|
43
|
+
function isContinuumDaoCommitteeProposer(addr2) {
|
|
44
|
+
if (!addr2 || !isConfiguredAddress(addr2)) return false;
|
|
45
45
|
try {
|
|
46
|
-
const a = viem.getAddress(
|
|
46
|
+
const a = viem.getAddress(addr2);
|
|
47
47
|
return exports.CONTINUUM_DAO_COMMITTEE_PROPOSERS.some((c) => c === a);
|
|
48
48
|
} catch {
|
|
49
49
|
return false;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
function isConfiguredAddress(
|
|
53
|
-
if (!
|
|
52
|
+
function isConfiguredAddress(addr2) {
|
|
53
|
+
if (!addr2?.trim()) return false;
|
|
54
54
|
try {
|
|
55
|
-
return viem.getAddress(
|
|
55
|
+
return viem.getAddress(addr2) !== viem.zeroAddress;
|
|
56
56
|
} catch {
|
|
57
57
|
return false;
|
|
58
58
|
}
|
|
@@ -74,6 +74,10 @@ function votingEscrowAddressOnEvmChain(chainId) {
|
|
|
74
74
|
const ve = continuumDaoDeployment(chainId)?.votingEscrow;
|
|
75
75
|
return ve && isConfiguredAddress(ve) ? viem.getAddress(ve) : null;
|
|
76
76
|
}
|
|
77
|
+
function votingEscrowMarketplaceAddressOnEvmChain(chainId) {
|
|
78
|
+
if (chainId !== exports.CONTINUUM_DAO_LINEA_CHAIN_ID) return null;
|
|
79
|
+
return exports.VOTING_ESCROW_MARKETPLACE_LINEA_ADDRESS;
|
|
80
|
+
}
|
|
77
81
|
function governorAddressOnEvmChain(chainId) {
|
|
78
82
|
const gov = continuumDaoDeployment(chainId)?.governor;
|
|
79
83
|
return gov && isConfiguredAddress(gov) ? viem.getAddress(gov) : null;
|
|
@@ -136,7 +140,7 @@ function listContinuumDaoDefaultAssets() {
|
|
|
136
140
|
}
|
|
137
141
|
return out;
|
|
138
142
|
}
|
|
139
|
-
exports.CONTINUUM_DAO_PROTOCOL_ID = void 0; exports.CONTINUUM_DAO_ETHEREUM_CHAIN_ID = void 0; exports.CONTINUUM_DAO_LINEA_CHAIN_ID = void 0; exports.CONTINUUM_DAO_LINEA_SEPOLIA_CHAIN_ID = void 0; exports.CTM_TOKEN_NAME = void 0; exports.CTM_TOKEN_SYMBOL = void 0; exports.VECTM_TOKEN_NAME = void 0; exports.VECTM_TOKEN_SYMBOL = void 0; exports.CTM_TOKEN_DECIMALS = void 0; exports.WEEK_SECONDS = void 0; exports.MAXTIME_SECONDS = void 0; exports.VECTM_MAX_LOCK_WEEKS = void 0; exports.VECTM_DEFAULT_MINIMUM_LOCK_WEI = void 0; exports.VECTM_LIQ_MIN_LOCKED_WEI = void 0; exports.VECTM_LIQ_PENALTY_NUM = void 0; exports.VECTM_LIQ_PENALTY_DEN = void 0; var UNSET; exports.CTM_TOKEN_ADDRESS = void 0; exports.VOTING_ESCROW_LINEA_ADDRESS = void 0; exports.CONTINUUM_DAO_LINEA_GOVERNOR_ADDRESS = void 0; exports.CONTINUUM_DAO_LINEA_GOVERNOR_LEGACY_ADDRESS = void 0; exports.CONTINUUM_DAO_COMMITTEE_PROPOSERS = void 0; exports.CONTINUUM_DAO_DEPLOYMENTS = void 0; exports.CONTINUUM_DAO_GOVERNANCE_API = void 0;
|
|
143
|
+
exports.CONTINUUM_DAO_PROTOCOL_ID = void 0; exports.CONTINUUM_DAO_ETHEREUM_CHAIN_ID = void 0; exports.CONTINUUM_DAO_LINEA_CHAIN_ID = void 0; exports.CONTINUUM_DAO_LINEA_SEPOLIA_CHAIN_ID = void 0; exports.CTM_TOKEN_NAME = void 0; exports.CTM_TOKEN_SYMBOL = void 0; exports.VECTM_TOKEN_NAME = void 0; exports.VECTM_TOKEN_SYMBOL = void 0; exports.CTM_TOKEN_DECIMALS = void 0; exports.WEEK_SECONDS = void 0; exports.MAXTIME_SECONDS = void 0; exports.VECTM_MAX_LOCK_WEEKS = void 0; exports.VECTM_DEFAULT_MINIMUM_LOCK_WEI = void 0; exports.VECTM_LIQ_MIN_LOCKED_WEI = void 0; exports.VECTM_LIQ_PENALTY_NUM = void 0; exports.VECTM_LIQ_PENALTY_DEN = void 0; var UNSET; exports.CTM_TOKEN_ADDRESS = void 0; exports.VOTING_ESCROW_LINEA_ADDRESS = void 0; exports.MULTISIGN_AGENT_WALLET_LINEA_ADDRESS = void 0; exports.CTM_FEE_RATE_SCALE = void 0; exports.VOTING_ESCROW_MARKETPLACE_LINEA_ADDRESS = void 0; exports.VOTING_ESCROW_MARKETPLACE_START_BLOCK = void 0; exports.MARKETPLACE_WETH_LINEA_ADDRESS = void 0; exports.MARKETPLACE_USDC_LINEA_ADDRESS = void 0; exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID = void 0; exports.CONTINUUM_DAO_LINEA_GOVERNOR_ADDRESS = void 0; exports.CONTINUUM_DAO_LINEA_GOVERNOR_LEGACY_ADDRESS = void 0; exports.CONTINUUM_DAO_COMMITTEE_PROPOSERS = void 0; exports.CONTINUUM_DAO_DEPLOYMENTS = void 0; exports.CONTINUUM_DAO_GOVERNANCE_API = void 0; exports.CONTINUUM_DAO_MARKETPLACE_API = void 0;
|
|
140
144
|
var init_constants = __esm({
|
|
141
145
|
"src/protocols/evm/continuum-dao/constants.ts"() {
|
|
142
146
|
init_chainIdParse();
|
|
@@ -165,6 +169,13 @@ var init_constants = __esm({
|
|
|
165
169
|
};
|
|
166
170
|
exports.CTM_TOKEN_ADDRESS = viem.getAddress("0x2026027054F5beBCEB650aBD62dC623e327658e7");
|
|
167
171
|
exports.VOTING_ESCROW_LINEA_ADDRESS = viem.getAddress("0x221EC90B3B083A8501A37bdeb7035CeaedF3C31f");
|
|
172
|
+
exports.MULTISIGN_AGENT_WALLET_LINEA_ADDRESS = viem.getAddress("0x4ebd7cCBe32a51d1638cFE90E8eD1c4BdF42f729");
|
|
173
|
+
exports.CTM_FEE_RATE_SCALE = 1000n;
|
|
174
|
+
exports.VOTING_ESCROW_MARKETPLACE_LINEA_ADDRESS = viem.getAddress("0x92557d38beAe4658d3c03A02F349FFB60c3bfFA5");
|
|
175
|
+
exports.VOTING_ESCROW_MARKETPLACE_START_BLOCK = 32100001n;
|
|
176
|
+
exports.MARKETPLACE_WETH_LINEA_ADDRESS = viem.getAddress("0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f");
|
|
177
|
+
exports.MARKETPLACE_USDC_LINEA_ADDRESS = viem.getAddress("0x176211869cA2b568f2A7D4EE941E073a821EE1ff");
|
|
178
|
+
exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID = "continuum-dao-marketplace";
|
|
168
179
|
exports.CONTINUUM_DAO_LINEA_GOVERNOR_ADDRESS = viem.getAddress("0x76FF2CB03175900F1D83328C82D27EA9aeaF2355");
|
|
169
180
|
exports.CONTINUUM_DAO_LINEA_GOVERNOR_LEGACY_ADDRESS = viem.getAddress("0x4800F9f1dC1b6daCA841B71E0531F547D374168E");
|
|
170
181
|
exports.CONTINUUM_DAO_COMMITTEE_PROPOSERS = [
|
|
@@ -185,6 +196,7 @@ var init_constants = __esm({
|
|
|
185
196
|
}
|
|
186
197
|
};
|
|
187
198
|
exports.CONTINUUM_DAO_GOVERNANCE_API = "https://app-api.continuumdao.org";
|
|
199
|
+
exports.CONTINUUM_DAO_MARKETPLACE_API = exports.CONTINUUM_DAO_GOVERNANCE_API;
|
|
188
200
|
}
|
|
189
201
|
});
|
|
190
202
|
function defiEvmTransport(rpcUrl, opts) {
|
|
@@ -606,25 +618,25 @@ async function forumFetch(path, init = {}) {
|
|
|
606
618
|
return body;
|
|
607
619
|
}
|
|
608
620
|
async function continuumDaoForumResolve(args) {
|
|
609
|
-
const
|
|
610
|
-
if (args.url)
|
|
611
|
-
if (args.tid != null)
|
|
612
|
-
return forumFetch(`/api/continuum/forum/resolve?${
|
|
621
|
+
const qs2 = new URLSearchParams();
|
|
622
|
+
if (args.url) qs2.set("url", String(args.url));
|
|
623
|
+
if (args.tid != null) qs2.set("tid", String(args.tid));
|
|
624
|
+
return forumFetch(`/api/continuum/forum/resolve?${qs2}`, { forumUrl: args.forumUrl });
|
|
613
625
|
}
|
|
614
626
|
async function continuumDaoForumFetchThread(args) {
|
|
615
|
-
const
|
|
616
|
-
if (args.url)
|
|
617
|
-
if (args.tid != null)
|
|
618
|
-
if (args.index != null)
|
|
619
|
-
if (args.start != null)
|
|
620
|
-
if (args.limit != null)
|
|
621
|
-
return forumFetch(`/api/continuum/forum/thread?${
|
|
627
|
+
const qs2 = new URLSearchParams();
|
|
628
|
+
if (args.url) qs2.set("url", String(args.url));
|
|
629
|
+
if (args.tid != null) qs2.set("tid", String(args.tid));
|
|
630
|
+
if (args.index != null) qs2.set("index", String(args.index));
|
|
631
|
+
if (args.start != null) qs2.set("start", String(args.start));
|
|
632
|
+
if (args.limit != null) qs2.set("limit", String(args.limit));
|
|
633
|
+
return forumFetch(`/api/continuum/forum/thread?${qs2}`, { forumUrl: args.forumUrl });
|
|
622
634
|
}
|
|
623
635
|
async function continuumDaoForumReplyCount(args) {
|
|
624
|
-
const
|
|
625
|
-
if (args.url)
|
|
626
|
-
if (args.tid != null)
|
|
627
|
-
return forumFetch(`/api/continuum/forum/thread/replies?${
|
|
636
|
+
const qs2 = new URLSearchParams();
|
|
637
|
+
if (args.url) qs2.set("url", String(args.url));
|
|
638
|
+
if (args.tid != null) qs2.set("tid", String(args.tid));
|
|
639
|
+
return forumFetch(`/api/continuum/forum/thread/replies?${qs2}`, { forumUrl: args.forumUrl });
|
|
628
640
|
}
|
|
629
641
|
async function continuumDaoForumFetchPost(args) {
|
|
630
642
|
return forumFetch(`/api/continuum/forum/post?pid=${encodeURIComponent(String(args.pid))}`, {
|
|
@@ -650,22 +662,22 @@ function assertContinuumDaoForumRecentInput(args) {
|
|
|
650
662
|
}
|
|
651
663
|
async function continuumDaoForumSearch(args) {
|
|
652
664
|
assertContinuumDaoForumSearchInput(args);
|
|
653
|
-
const
|
|
654
|
-
if (args.query?.trim())
|
|
655
|
-
if (args.hours != null)
|
|
656
|
-
if (args.since?.trim())
|
|
657
|
-
if (args.start != null)
|
|
658
|
-
if (args.limit != null)
|
|
659
|
-
return forumFetch(`/api/continuum/forum/search?${
|
|
665
|
+
const qs2 = new URLSearchParams();
|
|
666
|
+
if (args.query?.trim()) qs2.set("query", args.query.trim());
|
|
667
|
+
if (args.hours != null) qs2.set("hours", String(args.hours));
|
|
668
|
+
if (args.since?.trim()) qs2.set("since", args.since.trim());
|
|
669
|
+
if (args.start != null) qs2.set("start", String(args.start));
|
|
670
|
+
if (args.limit != null) qs2.set("limit", String(args.limit));
|
|
671
|
+
return forumFetch(`/api/continuum/forum/search?${qs2}`, { forumUrl: args.forumUrl });
|
|
660
672
|
}
|
|
661
673
|
async function continuumDaoForumRecent(args) {
|
|
662
674
|
assertContinuumDaoForumRecentInput(args);
|
|
663
|
-
const
|
|
664
|
-
if (args.hours != null)
|
|
665
|
-
if (args.since?.trim())
|
|
666
|
-
if (args.start != null)
|
|
667
|
-
if (args.limit != null)
|
|
668
|
-
return forumFetch(`/api/continuum/forum/recent?${
|
|
675
|
+
const qs2 = new URLSearchParams();
|
|
676
|
+
if (args.hours != null) qs2.set("hours", String(args.hours));
|
|
677
|
+
if (args.since?.trim()) qs2.set("since", args.since.trim());
|
|
678
|
+
if (args.start != null) qs2.set("start", String(args.start));
|
|
679
|
+
if (args.limit != null) qs2.set("limit", String(args.limit));
|
|
680
|
+
return forumFetch(`/api/continuum/forum/recent?${qs2}`, {
|
|
669
681
|
forumUrl: args.forumUrl,
|
|
670
682
|
ticket: args.ticket
|
|
671
683
|
});
|
|
@@ -699,10 +711,10 @@ async function continuumDaoForumDelete(args) {
|
|
|
699
711
|
});
|
|
700
712
|
}
|
|
701
713
|
async function continuumDaoForumUserPostIds(args) {
|
|
702
|
-
const
|
|
703
|
-
if (args.start != null)
|
|
704
|
-
if (args.limit != null)
|
|
705
|
-
return forumFetch(`/api/continuum/forum/user/posts?${
|
|
714
|
+
const qs2 = new URLSearchParams({ username: args.username });
|
|
715
|
+
if (args.start != null) qs2.set("start", String(args.start));
|
|
716
|
+
if (args.limit != null) qs2.set("limit", String(args.limit));
|
|
717
|
+
return forumFetch(`/api/continuum/forum/user/posts?${qs2}`, { forumUrl: args.forumUrl });
|
|
706
718
|
}
|
|
707
719
|
async function continuumDaoForumReply(args) {
|
|
708
720
|
return forumFetch("/api/continuum/forum/reply", {
|
|
@@ -773,11 +785,11 @@ async function continuumDaoForumUnread(args) {
|
|
|
773
785
|
if (!args.ticket?.trim()) {
|
|
774
786
|
throw new Error("ticket is required to list unread forum topics");
|
|
775
787
|
}
|
|
776
|
-
const
|
|
777
|
-
if (args.filter?.trim())
|
|
778
|
-
if (args.start != null)
|
|
779
|
-
if (args.limit != null)
|
|
780
|
-
const suffix =
|
|
788
|
+
const qs2 = new URLSearchParams();
|
|
789
|
+
if (args.filter?.trim()) qs2.set("filter", args.filter.trim());
|
|
790
|
+
if (args.start != null) qs2.set("start", String(args.start));
|
|
791
|
+
if (args.limit != null) qs2.set("limit", String(args.limit));
|
|
792
|
+
const suffix = qs2.toString() ? `?${qs2}` : "";
|
|
781
793
|
return forumFetch(`/api/continuum/forum/unread${suffix}`, {
|
|
782
794
|
forumUrl: args.forumUrl,
|
|
783
795
|
ticket: args.ticket
|
|
@@ -926,12 +938,12 @@ async function continuumDaoForumSignInEligible(args) {
|
|
|
926
938
|
};
|
|
927
939
|
}
|
|
928
940
|
async function continuumDaoForumSignInNonce(args) {
|
|
929
|
-
const
|
|
941
|
+
const qs2 = new URLSearchParams({
|
|
930
942
|
address: args.address,
|
|
931
943
|
nodeKey: args.nodeKey || "",
|
|
932
944
|
username: args.username || ""
|
|
933
945
|
});
|
|
934
|
-
return forumFetch(`/api/continuum/eip712/nonce?${
|
|
946
|
+
return forumFetch(`/api/continuum/eip712/nonce?${qs2}`, { forumUrl: args.forumUrl });
|
|
935
947
|
}
|
|
936
948
|
async function buildEvmMultisignBodyContinuumDaoForumSignIn(args) {
|
|
937
949
|
const owner = viem.getAddress(args.executorAddress);
|
|
@@ -2295,9 +2307,9 @@ function parseBackendProposal(raw) {
|
|
|
2295
2307
|
committeeProposer: proposer ? isContinuumDaoCommitteeProposer(proposer) : void 0
|
|
2296
2308
|
};
|
|
2297
2309
|
}
|
|
2298
|
-
function isLegacyContinuumDaoGovernor(
|
|
2299
|
-
if (!
|
|
2300
|
-
return viem.getAddress(
|
|
2310
|
+
function isLegacyContinuumDaoGovernor(addr2) {
|
|
2311
|
+
if (!addr2 || !isConfiguredAddress(addr2)) return false;
|
|
2312
|
+
return viem.getAddress(addr2) === exports.CONTINUUM_DAO_LINEA_GOVERNOR_LEGACY_ADDRESS;
|
|
2301
2313
|
}
|
|
2302
2314
|
function summarizeLiveProposals(result) {
|
|
2303
2315
|
if (result.overlay === "backend-only") {
|
|
@@ -2474,6 +2486,45 @@ function registerProtocolModule(mod) {
|
|
|
2474
2486
|
|
|
2475
2487
|
// src/protocols/evm/continuum-dao/index.ts
|
|
2476
2488
|
init_constants();
|
|
2489
|
+
|
|
2490
|
+
// src/protocols/evm/continuum-dao/marketplaceModule.ts
|
|
2491
|
+
init_constants();
|
|
2492
|
+
var common = ["keyGen", "purposeText", "useCustomGas"];
|
|
2493
|
+
var continuumDaoMarketplaceProtocolModule = {
|
|
2494
|
+
id: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID,
|
|
2495
|
+
chainCategory: "evm",
|
|
2496
|
+
isChainSupported(ctx) {
|
|
2497
|
+
if (ctx.chainCategory !== "evm") return false;
|
|
2498
|
+
const n = typeof ctx.chainId === "number" ? ctx.chainId : Number.parseInt(String(ctx.chainId), 10);
|
|
2499
|
+
return n === exports.CONTINUUM_DAO_LINEA_CHAIN_ID;
|
|
2500
|
+
},
|
|
2501
|
+
isTokenSupported(token) {
|
|
2502
|
+
return token.category === "evm" && (token.kind === "erc20" || token.kind === "erc721");
|
|
2503
|
+
},
|
|
2504
|
+
actions: [
|
|
2505
|
+
{ id: "continuum-dao-marketplace.fetch-config", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "Marketplace payment tokens, durations, and fees", commonParams: [], params: {} },
|
|
2506
|
+
{ id: "continuum-dao-marketplace.search", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "Rank veCTMs for sale by price, locked CTM, or unlock time", commonParams: [], params: {} },
|
|
2507
|
+
{ id: "continuum-dao-marketplace.fee-alternative", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "One qualifying direct listing beside 12 times the KeyGen monthly fee", commonParams: [], params: {} },
|
|
2508
|
+
{ id: "continuum-dao-marketplace.fetch-listings", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "Open listings, or past sales when includeInactive is set", commonParams: [], params: {} },
|
|
2509
|
+
{ id: "continuum-dao-marketplace.fetch-offerings", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "Open offerings, or closed offers when includeInactive is set", commonParams: [], params: {} },
|
|
2510
|
+
{ id: "continuum-dao-marketplace.fetch-auctions", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "Live auctions, or settled auctions when includeInactive is set. Each row includes bids.", commonParams: [], params: {} },
|
|
2511
|
+
{ id: "continuum-dao-marketplace.fetch-token", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "One veCTM: live orders plus history of sales and auctions", commonParams: [], params: { tokenId: { type: "string", required: true, description: "veCTM token id" } } },
|
|
2512
|
+
{ id: "continuum-dao-marketplace.fetch-activity", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "An address\u2019s sales, buys, and auctions including bids", commonParams: [], params: { address: { type: "string", required: true, description: "KeyGen or wallet" } } },
|
|
2513
|
+
{ id: "continuum-dao-marketplace.fetch-fee-preview", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "Protocol fee for a price and veCTM", commonParams: [], params: {} },
|
|
2514
|
+
{ id: "continuum-dao-marketplace.create-listing", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "Approve veCTM if needed and create a listing", commonParams: [...common], params: { tokenId: { type: "string", required: true, description: "veCTM token id" }, askWei: { type: "string", required: true, description: "Ask in payment-token wei" } } },
|
|
2515
|
+
{ id: "continuum-dao-marketplace.delist", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "Delist an open listing", commonParams: [...common], params: { tokenId: { type: "string", required: true, description: "veCTM token id" } } },
|
|
2516
|
+
{ id: "continuum-dao-marketplace.fulfill-listing", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "Buy a listed veCTM", commonParams: [...common], params: { tokenId: { type: "string", required: true, description: "veCTM token id" } } },
|
|
2517
|
+
{ id: "continuum-dao-marketplace.create-offering", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "Make an offering on a veCTM", commonParams: [...common], params: { tokenId: { type: "string", required: true, description: "veCTM token id" } } },
|
|
2518
|
+
{ id: "continuum-dao-marketplace.rescind", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "Rescind an open offering", commonParams: [...common], params: { tokenId: { type: "string", required: true, description: "veCTM token id" } } },
|
|
2519
|
+
{ id: "continuum-dao-marketplace.fulfill-offering", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "Accept an offering on a veCTM you own", commonParams: [...common], params: { tokenId: { type: "string", required: true, description: "veCTM token id" } } },
|
|
2520
|
+
{ id: "continuum-dao-marketplace.create-auction", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "Escrow a veCTM into an auction", commonParams: [...common], params: { tokenId: { type: "string", required: true, description: "veCTM token id" } } },
|
|
2521
|
+
{ id: "continuum-dao-marketplace.cancel-auction", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "Cancel a pending auction with no bids", commonParams: [...common], params: { tokenId: { type: "string", required: true, description: "veCTM token id" } } },
|
|
2522
|
+
{ id: "continuum-dao-marketplace.auction-bid", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "Bid on a live auction", commonParams: [...common], params: { tokenId: { type: "string", required: true, description: "veCTM token id" } } },
|
|
2523
|
+
{ id: "continuum-dao-marketplace.settle-auction", protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID, chainCategory: "evm", description: "Settle a completed or expired auction", commonParams: [...common], params: { tokenId: { type: "string", required: true, description: "veCTM token id" } } }
|
|
2524
|
+
]
|
|
2525
|
+
};
|
|
2526
|
+
|
|
2527
|
+
// src/protocols/evm/continuum-dao/index.ts
|
|
2477
2528
|
init_constants();
|
|
2478
2529
|
|
|
2479
2530
|
// src/protocols/evm/continuum-dao/escrowRules.ts
|
|
@@ -2769,13 +2820,13 @@ async function readVeCtmLockState(args) {
|
|
|
2769
2820
|
let attached = false;
|
|
2770
2821
|
if (isConfiguredAddress(nodeProperties)) {
|
|
2771
2822
|
try {
|
|
2772
|
-
const
|
|
2823
|
+
const attachedKey2 = await client.readContract({
|
|
2773
2824
|
address: viem.getAddress(nodeProperties),
|
|
2774
2825
|
abi: nodePropsAbi,
|
|
2775
2826
|
functionName: "attachedKeyGen",
|
|
2776
2827
|
args: [args.tokenId]
|
|
2777
2828
|
});
|
|
2778
|
-
attached =
|
|
2829
|
+
attached = attachedKey2 !== viem.zeroAddress;
|
|
2779
2830
|
} catch {
|
|
2780
2831
|
attached = false;
|
|
2781
2832
|
}
|
|
@@ -2943,7 +2994,7 @@ async function preflightAttachVeCtm(args) {
|
|
|
2943
2994
|
}
|
|
2944
2995
|
if (isConfiguredAddress(nodeProperties)) {
|
|
2945
2996
|
const np = viem.getAddress(nodeProperties);
|
|
2946
|
-
const [
|
|
2997
|
+
const [attachedKey2, attachedForKey] = await Promise.all([
|
|
2947
2998
|
client.readContract({
|
|
2948
2999
|
address: np,
|
|
2949
3000
|
abi: nodePropsAbi,
|
|
@@ -2957,7 +3008,7 @@ async function preflightAttachVeCtm(args) {
|
|
|
2957
3008
|
args: [executor]
|
|
2958
3009
|
})
|
|
2959
3010
|
]);
|
|
2960
|
-
if (
|
|
3011
|
+
if (attachedKey2 !== viem.zeroAddress) {
|
|
2961
3012
|
throw new Error(`veCTM #${args.tokenId} is already attached. You cannot replace an attached NFT.`);
|
|
2962
3013
|
}
|
|
2963
3014
|
if (attachedForKey !== 0n) {
|
|
@@ -2974,7 +3025,7 @@ async function preflightAttachVeCtm(args) {
|
|
|
2974
3025
|
}
|
|
2975
3026
|
async function preflightRequestDetach(args) {
|
|
2976
3027
|
const client = publicClient(args.rpcUrl, args.chainId);
|
|
2977
|
-
const [
|
|
3028
|
+
const [attachedKey2, alreadyRequested] = await Promise.all([
|
|
2978
3029
|
client.readContract({
|
|
2979
3030
|
address: args.nodeProperties,
|
|
2980
3031
|
abi: nodePropsAbi,
|
|
@@ -2988,7 +3039,7 @@ async function preflightRequestDetach(args) {
|
|
|
2988
3039
|
args: [args.tokenId]
|
|
2989
3040
|
})
|
|
2990
3041
|
]);
|
|
2991
|
-
if (
|
|
3042
|
+
if (attachedKey2 === viem.zeroAddress) {
|
|
2992
3043
|
throw new Error(`veCTM #${args.tokenId} is not attached to a node.`);
|
|
2993
3044
|
}
|
|
2994
3045
|
if (alreadyRequested) {
|
|
@@ -2996,9 +3047,9 @@ async function preflightRequestDetach(args) {
|
|
|
2996
3047
|
`Detach already requested for veCTM #${args.tokenId}. The NFT stays attached until governance executes detach.`
|
|
2997
3048
|
);
|
|
2998
3049
|
}
|
|
2999
|
-
if (viem.getAddress(
|
|
3050
|
+
if (viem.getAddress(attachedKey2) !== viem.getAddress(args.owner)) {
|
|
3000
3051
|
throw new Error(
|
|
3001
|
-
`Request detach from the attached KeyGen (${viem.getAddress(
|
|
3052
|
+
`Request detach from the attached KeyGen (${viem.getAddress(attachedKey2)}).`
|
|
3002
3053
|
);
|
|
3003
3054
|
}
|
|
3004
3055
|
}
|
|
@@ -3852,8 +3903,8 @@ function extractAbiFromSourcifyFiles(data) {
|
|
|
3852
3903
|
if (!label.includes("metadata.json") && f.name !== "metadata.json") continue;
|
|
3853
3904
|
if (typeof f.content !== "string") continue;
|
|
3854
3905
|
try {
|
|
3855
|
-
const
|
|
3856
|
-
const abi = extractAbiFromUnknown(
|
|
3906
|
+
const meta4 = JSON.parse(f.content);
|
|
3907
|
+
const abi = extractAbiFromUnknown(meta4);
|
|
3857
3908
|
if (abi) return abi;
|
|
3858
3909
|
} catch {
|
|
3859
3910
|
continue;
|
|
@@ -4713,6 +4764,2112 @@ async function continuumDaoFetchProposalVotes(args, deps) {
|
|
|
4713
4764
|
|
|
4714
4765
|
// src/protocols/evm/continuum-dao/index.ts
|
|
4715
4766
|
init_forum();
|
|
4767
|
+
|
|
4768
|
+
// src/protocols/evm/continuum-dao/marketplaceTypes.ts
|
|
4769
|
+
var MARKET_ORDER_STATUS = [
|
|
4770
|
+
"NonExistent",
|
|
4771
|
+
"Open",
|
|
4772
|
+
"Fulfilled",
|
|
4773
|
+
"Expired",
|
|
4774
|
+
"DelistedOrRescinded",
|
|
4775
|
+
"LockAmountDecreased",
|
|
4776
|
+
"LockEndIncreased",
|
|
4777
|
+
"TokenApprovalRequired",
|
|
4778
|
+
"PaymentApprovalRequired",
|
|
4779
|
+
"KeyGenAttached"
|
|
4780
|
+
];
|
|
4781
|
+
var AUCTION_STATUS = [
|
|
4782
|
+
"NonExistent",
|
|
4783
|
+
"Pending",
|
|
4784
|
+
"Active",
|
|
4785
|
+
"Complete",
|
|
4786
|
+
"Sold",
|
|
4787
|
+
"Canceled",
|
|
4788
|
+
"Expired"
|
|
4789
|
+
];
|
|
4790
|
+
var FEE_TIER_NAMES = ["Black", "Gold", "Silver", "Bronze", "Blue"];
|
|
4791
|
+
function orderStatusName(code) {
|
|
4792
|
+
return MARKET_ORDER_STATUS[code] ?? "NonExistent";
|
|
4793
|
+
}
|
|
4794
|
+
function auctionStatusName(code) {
|
|
4795
|
+
return AUCTION_STATUS[code] ?? "NonExistent";
|
|
4796
|
+
}
|
|
4797
|
+
function addr(value) {
|
|
4798
|
+
try {
|
|
4799
|
+
return viem.getAddress(value);
|
|
4800
|
+
} catch {
|
|
4801
|
+
return value;
|
|
4802
|
+
}
|
|
4803
|
+
}
|
|
4804
|
+
function same(a, b) {
|
|
4805
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
4806
|
+
}
|
|
4807
|
+
function deadlineAt(unix) {
|
|
4808
|
+
const n = Number(unix);
|
|
4809
|
+
if (!Number.isFinite(n) || n <= 0) return "";
|
|
4810
|
+
return new Date(n * 1e3).toISOString();
|
|
4811
|
+
}
|
|
4812
|
+
function blankOrder(kind, tokenId, creator, index) {
|
|
4813
|
+
return {
|
|
4814
|
+
kind,
|
|
4815
|
+
tokenId,
|
|
4816
|
+
onchainIndex: index,
|
|
4817
|
+
creator: addr(creator),
|
|
4818
|
+
paymentToken: viem.zeroAddress,
|
|
4819
|
+
price: "0",
|
|
4820
|
+
deadlineUnix: "0",
|
|
4821
|
+
deadlineAt: "",
|
|
4822
|
+
snapshotAmount: "0",
|
|
4823
|
+
snapshotEnd: "0",
|
|
4824
|
+
storedStatus: "Open",
|
|
4825
|
+
protocolStatus: "Open"
|
|
4826
|
+
};
|
|
4827
|
+
}
|
|
4828
|
+
function blankAuction(tokenId, seller, index) {
|
|
4829
|
+
return {
|
|
4830
|
+
tokenId,
|
|
4831
|
+
onchainIndex: index,
|
|
4832
|
+
seller: addr(seller),
|
|
4833
|
+
paymentToken: viem.zeroAddress,
|
|
4834
|
+
reservePrice: "0",
|
|
4835
|
+
minimumBidIncrement: "0",
|
|
4836
|
+
highestBid: "0",
|
|
4837
|
+
highestBidder: null,
|
|
4838
|
+
deadlineUnix: "0",
|
|
4839
|
+
deadlineAt: "",
|
|
4840
|
+
storedStatus: "Pending",
|
|
4841
|
+
derivedStatus: "Pending",
|
|
4842
|
+
needsSettle: false,
|
|
4843
|
+
bids: []
|
|
4844
|
+
};
|
|
4845
|
+
}
|
|
4846
|
+
function latestOpenOrder(rows, kind, tokenId, creator) {
|
|
4847
|
+
for (let i = rows.length - 1; i >= 0; i--) {
|
|
4848
|
+
const row = rows[i];
|
|
4849
|
+
if (row.kind === kind && row.tokenId === tokenId && same(row.creator, creator) && row.storedStatus === "Open") {
|
|
4850
|
+
return row;
|
|
4851
|
+
}
|
|
4852
|
+
}
|
|
4853
|
+
return void 0;
|
|
4854
|
+
}
|
|
4855
|
+
function latestAuction(rows, tokenId, seller) {
|
|
4856
|
+
for (let i = rows.length - 1; i >= 0; i--) {
|
|
4857
|
+
const row = rows[i];
|
|
4858
|
+
if (row.tokenId === tokenId && same(row.seller, seller)) return row;
|
|
4859
|
+
}
|
|
4860
|
+
return void 0;
|
|
4861
|
+
}
|
|
4862
|
+
function applyMarketplaceEvent(book, ev) {
|
|
4863
|
+
const listingSeq = book.listings.reduce((max, row) => Math.max(max, Number(row.onchainIndex) || 0), 0);
|
|
4864
|
+
const offeringSeq = book.offerings.reduce((max, row) => Math.max(max, Number(row.onchainIndex) || 0), 0);
|
|
4865
|
+
const auctionSeq = book.auctions.reduce((max, row) => Math.max(max, Number(row.onchainIndex) || 0), 0);
|
|
4866
|
+
const next = (seq) => String(seq + 1);
|
|
4867
|
+
if (ev.name === "ListingCreated" || ev.name === "OfferingCreated") {
|
|
4868
|
+
const kind = ev.name === "ListingCreated" ? "Listing" : "Offering";
|
|
4869
|
+
const rows = kind === "Listing" ? book.listings : book.offerings;
|
|
4870
|
+
const prev = latestOpenOrder(rows, kind, ev.tokenId, ev.actor);
|
|
4871
|
+
if (prev) {
|
|
4872
|
+
prev.storedStatus = "DelistedOrRescinded";
|
|
4873
|
+
prev.protocolStatus = "DelistedOrRescinded";
|
|
4874
|
+
prev.closedTx = ev.tx;
|
|
4875
|
+
prev.closedBlock = ev.block;
|
|
4876
|
+
}
|
|
4877
|
+
const row = blankOrder(kind, ev.tokenId, ev.actor, next(kind === "Listing" ? listingSeq : offeringSeq));
|
|
4878
|
+
row.paymentToken = addr(ev.paymentToken);
|
|
4879
|
+
row.price = ev.amount;
|
|
4880
|
+
row.deadlineUnix = ev.deadline;
|
|
4881
|
+
row.deadlineAt = deadlineAt(ev.deadline);
|
|
4882
|
+
row.createdTx = ev.tx;
|
|
4883
|
+
row.createdBlock = ev.block;
|
|
4884
|
+
if (kind === "Listing") row.seller = addr(ev.actor);
|
|
4885
|
+
else row.buyer = addr(ev.actor);
|
|
4886
|
+
rows.push(row);
|
|
4887
|
+
return;
|
|
4888
|
+
}
|
|
4889
|
+
if (ev.name === "Delisted" || ev.name === "Rescinded") {
|
|
4890
|
+
const kind = ev.name === "Delisted" ? "Listing" : "Offering";
|
|
4891
|
+
const row = latestOpenOrder(kind === "Listing" ? book.listings : book.offerings, kind, ev.tokenId, ev.actor);
|
|
4892
|
+
if (row) {
|
|
4893
|
+
row.storedStatus = "DelistedOrRescinded";
|
|
4894
|
+
row.protocolStatus = "DelistedOrRescinded";
|
|
4895
|
+
row.closedTx = ev.tx;
|
|
4896
|
+
row.closedBlock = ev.block;
|
|
4897
|
+
}
|
|
4898
|
+
return;
|
|
4899
|
+
}
|
|
4900
|
+
if (ev.name === "ListingFulfilled" || ev.name === "OfferingFulfilled") {
|
|
4901
|
+
const kind = ev.name === "ListingFulfilled" ? "Listing" : "Offering";
|
|
4902
|
+
const actor = kind === "Listing" ? ev.seller : ev.buyer;
|
|
4903
|
+
const row = latestOpenOrder(kind === "Listing" ? book.listings : book.offerings, kind, ev.tokenId, actor);
|
|
4904
|
+
if (row) {
|
|
4905
|
+
row.storedStatus = "Fulfilled";
|
|
4906
|
+
row.protocolStatus = "Fulfilled";
|
|
4907
|
+
row.counterparty = addr(kind === "Listing" ? ev.buyer : ev.seller);
|
|
4908
|
+
row.seller = addr(ev.seller);
|
|
4909
|
+
row.buyer = addr(ev.buyer);
|
|
4910
|
+
row.fee = ev.fee;
|
|
4911
|
+
row.net = ev.net;
|
|
4912
|
+
row.closedTx = ev.tx;
|
|
4913
|
+
row.closedBlock = ev.block;
|
|
4914
|
+
}
|
|
4915
|
+
return;
|
|
4916
|
+
}
|
|
4917
|
+
if (ev.name === "AuctionCreated") {
|
|
4918
|
+
const prev = latestAuction(book.auctions, ev.tokenId, ev.actor);
|
|
4919
|
+
if (prev && (prev.storedStatus === "Pending" || prev.storedStatus === "Active")) {
|
|
4920
|
+
prev.storedStatus = "Canceled";
|
|
4921
|
+
prev.derivedStatus = "Canceled";
|
|
4922
|
+
prev.closedTx = ev.tx;
|
|
4923
|
+
prev.closedBlock = ev.block;
|
|
4924
|
+
}
|
|
4925
|
+
const row = blankAuction(ev.tokenId, ev.actor, next(auctionSeq));
|
|
4926
|
+
row.paymentToken = addr(ev.paymentToken);
|
|
4927
|
+
row.reservePrice = ev.amount;
|
|
4928
|
+
row.minimumBidIncrement = ev.minIncrement;
|
|
4929
|
+
row.deadlineUnix = ev.deadline;
|
|
4930
|
+
row.deadlineAt = deadlineAt(ev.deadline);
|
|
4931
|
+
row.createdTx = ev.tx;
|
|
4932
|
+
row.createdBlock = ev.block;
|
|
4933
|
+
book.auctions.push(row);
|
|
4934
|
+
return;
|
|
4935
|
+
}
|
|
4936
|
+
if (ev.name === "AuctionCanceled") {
|
|
4937
|
+
const row = latestAuction(book.auctions, ev.tokenId, ev.actor);
|
|
4938
|
+
if (row && row.storedStatus === "Pending") {
|
|
4939
|
+
row.storedStatus = "Canceled";
|
|
4940
|
+
row.derivedStatus = "Canceled";
|
|
4941
|
+
row.closedTx = ev.tx;
|
|
4942
|
+
row.closedBlock = ev.block;
|
|
4943
|
+
}
|
|
4944
|
+
return;
|
|
4945
|
+
}
|
|
4946
|
+
if (ev.name === "AuctionBid") {
|
|
4947
|
+
const row = latestAuction(book.auctions, ev.tokenId, ev.seller);
|
|
4948
|
+
if (!row || row.storedStatus !== "Pending" && row.storedStatus !== "Active") return;
|
|
4949
|
+
row.bids = [
|
|
4950
|
+
...row.bids,
|
|
4951
|
+
{
|
|
4952
|
+
bidder: addr(ev.buyer),
|
|
4953
|
+
price: ev.price,
|
|
4954
|
+
tx: ev.tx,
|
|
4955
|
+
timestamp: ev.timestamp ?? "0",
|
|
4956
|
+
logIndex: String(ev.logIndex),
|
|
4957
|
+
block: ev.block
|
|
4958
|
+
}
|
|
4959
|
+
];
|
|
4960
|
+
row.highestBid = ev.price;
|
|
4961
|
+
row.highestBidder = addr(ev.buyer);
|
|
4962
|
+
row.storedStatus = "Active";
|
|
4963
|
+
row.derivedStatus = "Active";
|
|
4964
|
+
return;
|
|
4965
|
+
}
|
|
4966
|
+
if (ev.name === "AuctionSettled") {
|
|
4967
|
+
const row = latestAuction(book.auctions, ev.tokenId, ev.seller);
|
|
4968
|
+
if (!row) return;
|
|
4969
|
+
const name = auctionStatusName(ev.finalStatus);
|
|
4970
|
+
row.storedStatus = name;
|
|
4971
|
+
row.derivedStatus = name;
|
|
4972
|
+
row.needsSettle = false;
|
|
4973
|
+
row.closedTx = ev.tx;
|
|
4974
|
+
row.closedBlock = ev.block;
|
|
4975
|
+
return;
|
|
4976
|
+
}
|
|
4977
|
+
if (ev.name === "AuctionSuccessful") {
|
|
4978
|
+
const row = latestAuction(book.auctions, ev.tokenId, ev.seller);
|
|
4979
|
+
if (!row) return;
|
|
4980
|
+
row.storedStatus = "Sold";
|
|
4981
|
+
row.derivedStatus = "Sold";
|
|
4982
|
+
row.buyer = addr(ev.buyer);
|
|
4983
|
+
row.highestBidder = addr(ev.buyer);
|
|
4984
|
+
row.highestBid = ev.price;
|
|
4985
|
+
row.fee = ev.fee;
|
|
4986
|
+
row.net = ev.net;
|
|
4987
|
+
row.needsSettle = false;
|
|
4988
|
+
row.closedTx = ev.tx;
|
|
4989
|
+
row.closedBlock = ev.block;
|
|
4990
|
+
}
|
|
4991
|
+
}
|
|
4992
|
+
function foldMarketplaceEvents(events, initial) {
|
|
4993
|
+
const book = {
|
|
4994
|
+
listings: [...initial?.listings ?? []],
|
|
4995
|
+
offerings: [...initial?.offerings ?? []],
|
|
4996
|
+
auctions: (initial?.auctions ?? []).map((row) => ({ ...row, bids: [...row.bids] }))
|
|
4997
|
+
};
|
|
4998
|
+
for (const ev of events) applyMarketplaceEvent(book, ev);
|
|
4999
|
+
return book;
|
|
5000
|
+
}
|
|
5001
|
+
function deriveAuctionStatus(auction, nowUnix) {
|
|
5002
|
+
const deadline = Number(auction.deadlineUnix);
|
|
5003
|
+
if (auction.storedStatus === "Pending" && Number.isFinite(deadline) && nowUnix >= deadline) return "Expired";
|
|
5004
|
+
if (auction.storedStatus === "Active" && Number.isFinite(deadline) && nowUnix >= deadline) return "Complete";
|
|
5005
|
+
return auction.derivedStatus || auction.storedStatus;
|
|
5006
|
+
}
|
|
5007
|
+
function applyDerivedStatuses(book, nowUnix) {
|
|
5008
|
+
return {
|
|
5009
|
+
listings: book.listings.map((row) => {
|
|
5010
|
+
const deadline = Number(row.deadlineUnix);
|
|
5011
|
+
if (row.storedStatus === "Open" && Number.isFinite(deadline) && nowUnix >= deadline) {
|
|
5012
|
+
return { ...row, protocolStatus: "Expired" };
|
|
5013
|
+
}
|
|
5014
|
+
return row;
|
|
5015
|
+
}),
|
|
5016
|
+
offerings: book.offerings.map((row) => {
|
|
5017
|
+
const deadline = Number(row.deadlineUnix);
|
|
5018
|
+
if (row.storedStatus === "Open" && Number.isFinite(deadline) && nowUnix >= deadline) {
|
|
5019
|
+
return { ...row, protocolStatus: "Expired" };
|
|
5020
|
+
}
|
|
5021
|
+
return row;
|
|
5022
|
+
}),
|
|
5023
|
+
auctions: book.auctions.map((row) => {
|
|
5024
|
+
const derived = deriveAuctionStatus(row, nowUnix);
|
|
5025
|
+
const needsSettle = derived === "Complete" || derived === "Expired";
|
|
5026
|
+
return { ...row, derivedStatus: derived, needsSettle };
|
|
5027
|
+
})
|
|
5028
|
+
};
|
|
5029
|
+
}
|
|
5030
|
+
function isLiveAuctionStatus(status) {
|
|
5031
|
+
return status === "Pending" || status === "Active" || status === "Complete";
|
|
5032
|
+
}
|
|
5033
|
+
function isOpenOrder(row) {
|
|
5034
|
+
return row.storedStatus === "Open" && row.protocolStatus === "Open";
|
|
5035
|
+
}
|
|
5036
|
+
var marketplaceAbi = viem.parseAbi([
|
|
5037
|
+
"function weth() view returns (address)",
|
|
5038
|
+
"function ve() view returns (address)",
|
|
5039
|
+
"function np() view returns (address)",
|
|
5040
|
+
"function gov() view returns (address)",
|
|
5041
|
+
"function minimumDuration() view returns (uint256)",
|
|
5042
|
+
"function maximumDuration() view returns (uint256)",
|
|
5043
|
+
"function isValidPaymentToken(address) view returns (bool)",
|
|
5044
|
+
"function feeLimitByTier(uint8) view returns (uint256)",
|
|
5045
|
+
"function feeRateByTier(uint8) view returns (uint256)",
|
|
5046
|
+
"function listingIndexByTokenSeller(uint256,address) view returns (uint256)",
|
|
5047
|
+
"function listingsByToken(uint256,uint256) view returns (uint256 price, uint256 deadline, uint256 snapshotAmount, uint256 snapshotEnd, address creator, address paymentToken, uint8 status, uint8 kind)",
|
|
5048
|
+
"function offeringIndexByTokenBuyer(uint256,address) view returns (uint256)",
|
|
5049
|
+
"function offeringsByToken(uint256,uint256) view returns (uint256 price, uint256 deadline, uint256 snapshotAmount, uint256 snapshotEnd, address creator, address paymentToken, uint8 status, uint8 kind)",
|
|
5050
|
+
"function auctionIndexByTokenSeller(uint256,address) view returns (uint256)",
|
|
5051
|
+
"function auctionsByToken(uint256,uint256) view returns (uint256 reservePrice, uint256 minimumBidIncrement, uint256 deadline, address seller, address paymentToken, address highestBidder, uint256 highestBid, uint8 status)",
|
|
5052
|
+
"function marketOrderStatus((uint256,uint256,uint256,uint256,address,address,uint8,uint8),uint256,uint256,address,uint256) view returns (uint8)",
|
|
5053
|
+
"function auctionStatus((uint256,uint256,uint256,address,address,address,uint256,uint8)) view returns (uint8)",
|
|
5054
|
+
"function createListing(uint256,address,uint256,uint256)",
|
|
5055
|
+
"function delist(uint256)",
|
|
5056
|
+
"function fulfillListing(uint256,address,address,uint256) payable",
|
|
5057
|
+
"function createOffering(uint256,address,uint256,uint256) payable",
|
|
5058
|
+
"function rescind(uint256)",
|
|
5059
|
+
"function fulfillOffering(uint256,address,address,uint256)",
|
|
5060
|
+
"function createAuction(uint256,address,uint256,uint256,uint256)",
|
|
5061
|
+
"function cancelAuction(uint256)",
|
|
5062
|
+
"function auctionBid(uint256,address,uint256) payable",
|
|
5063
|
+
"function settleAuction(uint256,address)",
|
|
5064
|
+
"event ListingCreated(uint256 indexed _tokenId, address indexed _listedBy, address indexed _paymentToken, uint256 _ask, uint256 _deadline)",
|
|
5065
|
+
"event ListingFulfilled(uint256 indexed _tokenId, address indexed _buyer, address indexed _seller, uint256 _ask, uint256 _netPrice, uint256 _fee)",
|
|
5066
|
+
"event Delisted(uint256 indexed _tokenId, address indexed _seller)",
|
|
5067
|
+
"event OfferingCreated(uint256 indexed _tokenId, address indexed _offeredBy, address indexed _paymentToken, uint256 _bid, uint256 _deadline)",
|
|
5068
|
+
"event OfferingFulfilled(uint256 indexed _tokenId, address indexed _buyer, address indexed _seller, uint256 _bid, uint256 _netPrice, uint256 _fee)",
|
|
5069
|
+
"event Rescinded(uint256 indexed _tokenId, address indexed _buyer)",
|
|
5070
|
+
"event AuctionCreated(uint256 indexed _tokenId, address indexed _createdBy, address indexed _paymentToken, uint256 _reservePrice, uint256 _minimumBidIncrement, uint256 _deadline)",
|
|
5071
|
+
"event AuctionCanceled(uint256 indexed _tokenId, address indexed _seller)",
|
|
5072
|
+
"event AuctionBid(uint256 indexed _tokenId, address indexed _seller, address indexed _buyer, uint256 _price)",
|
|
5073
|
+
"event AuctionSettled(uint256 indexed _tokenId, address indexed _seller, uint8 indexed _finalStatus)",
|
|
5074
|
+
"event AuctionSuccessful(uint256 indexed _tokenId, address indexed _seller, address indexed _buyer, uint256 _price, uint256 _fee, uint256 _net)"
|
|
5075
|
+
]);
|
|
5076
|
+
var marketplaceReadAbi = viem.parseAbi([
|
|
5077
|
+
"function ownerOf(uint256) view returns (address)",
|
|
5078
|
+
"function getApproved(uint256) view returns (address)",
|
|
5079
|
+
"function isApprovedForAll(address,address) view returns (bool)",
|
|
5080
|
+
"function approve(address,uint256)",
|
|
5081
|
+
"function locked(uint256) view returns (int128 amount, uint256 end)",
|
|
5082
|
+
"function allowance(address,address) view returns (uint256)",
|
|
5083
|
+
"function decimals() view returns (uint8)",
|
|
5084
|
+
"function symbol() view returns (string)",
|
|
5085
|
+
"function attachedKeyGen(uint256) view returns (address)"
|
|
5086
|
+
]);
|
|
5087
|
+
|
|
5088
|
+
// src/protocols/evm/continuum-dao/marketplacePlan.ts
|
|
5089
|
+
var MARKETPLACE_APPROVE_FALLBACK = 80000n;
|
|
5090
|
+
var MARKETPLACE_LISTING_FALLBACK = 280000n;
|
|
5091
|
+
var MARKETPLACE_FULFILL_FALLBACK = 450000n;
|
|
5092
|
+
var MARKETPLACE_OFFERING_FALLBACK = 320000n;
|
|
5093
|
+
var MARKETPLACE_AUCTION_CREATE_FALLBACK = 380000n;
|
|
5094
|
+
var MARKETPLACE_BID_FALLBACK = 280000n;
|
|
5095
|
+
var MARKETPLACE_SETTLE_FALLBACK = 400000n;
|
|
5096
|
+
function same2(a, b) {
|
|
5097
|
+
try {
|
|
5098
|
+
return viem.getAddress(a) === viem.getAddress(b);
|
|
5099
|
+
} catch {
|
|
5100
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
5101
|
+
}
|
|
5102
|
+
}
|
|
5103
|
+
function isWeth(snap, token) {
|
|
5104
|
+
return same2(token, snap.weth);
|
|
5105
|
+
}
|
|
5106
|
+
function keyGenOwnsVeCtm(snap, seller) {
|
|
5107
|
+
if (same2(snap.owner, snap.executor)) return true;
|
|
5108
|
+
if (seller && same2(seller, snap.executor)) return true;
|
|
5109
|
+
if (snap.executorOpenListing && same2(snap.owner, snap.executor)) return true;
|
|
5110
|
+
if (snap.executorLiveAuction) return true;
|
|
5111
|
+
return false;
|
|
5112
|
+
}
|
|
5113
|
+
function assertNotOwn(snap, seller, tokenId) {
|
|
5114
|
+
if (same2(snap.owner, snap.executor) || seller && same2(seller, snap.executor) || snap.executorLiveAuction) {
|
|
5115
|
+
throw new Error(`This KeyGen already owns veCTM #${tokenId.toString()} and cannot buy or bid on it.`);
|
|
5116
|
+
}
|
|
5117
|
+
}
|
|
5118
|
+
function assertDeadline(snap, deadline) {
|
|
5119
|
+
const min = snap.now + snap.minimumDuration;
|
|
5120
|
+
const max = snap.now + snap.maximumDuration;
|
|
5121
|
+
if (deadline < min || deadline > max) {
|
|
5122
|
+
throw new Error(`Deadline must be between ${min.toString()} and ${max.toString()} (unix seconds).`);
|
|
5123
|
+
}
|
|
5124
|
+
}
|
|
5125
|
+
function assertPayment(snap) {
|
|
5126
|
+
if (!snap.paymentTokenValid) throw new Error("This payment token is not accepted by the marketplace.");
|
|
5127
|
+
}
|
|
5128
|
+
function assertNotAttached(snap, tokenId) {
|
|
5129
|
+
if (snap.attachedKeyGen !== viem.zeroAddress) {
|
|
5130
|
+
throw new Error(`veCTM #${tokenId.toString()} has a KeyGen attached.`);
|
|
5131
|
+
}
|
|
5132
|
+
}
|
|
5133
|
+
function nftApproveStep(snap, tokenId) {
|
|
5134
|
+
if (snap.nftApproved) return null;
|
|
5135
|
+
return {
|
|
5136
|
+
to: snap.votingEscrow,
|
|
5137
|
+
data: viem.encodeFunctionData({
|
|
5138
|
+
abi: marketplaceReadAbi,
|
|
5139
|
+
functionName: "approve",
|
|
5140
|
+
args: [snap.marketplace, tokenId]
|
|
5141
|
+
}),
|
|
5142
|
+
value: 0n,
|
|
5143
|
+
fallbackGas: MARKETPLACE_APPROVE_FALLBACK,
|
|
5144
|
+
evmType: "continuum_dao_marketplace_nft_approve",
|
|
5145
|
+
name: "VotingEscrow.approve",
|
|
5146
|
+
extra: { tokenId: tokenId.toString(), operator: snap.marketplace }
|
|
5147
|
+
};
|
|
5148
|
+
}
|
|
5149
|
+
function parseApproveAbi() {
|
|
5150
|
+
return [
|
|
5151
|
+
{
|
|
5152
|
+
type: "function",
|
|
5153
|
+
name: "approve",
|
|
5154
|
+
stateMutability: "nonpayable",
|
|
5155
|
+
inputs: [
|
|
5156
|
+
{ name: "spender", type: "address" },
|
|
5157
|
+
{ name: "amount", type: "uint256" }
|
|
5158
|
+
],
|
|
5159
|
+
outputs: [{ name: "", type: "bool" }]
|
|
5160
|
+
}
|
|
5161
|
+
];
|
|
5162
|
+
}
|
|
5163
|
+
function erc20Approve(snap, token, amount) {
|
|
5164
|
+
if (snap.allowance >= amount) return null;
|
|
5165
|
+
return {
|
|
5166
|
+
to: token,
|
|
5167
|
+
data: viem.encodeFunctionData({
|
|
5168
|
+
abi: parseApproveAbi(),
|
|
5169
|
+
functionName: "approve",
|
|
5170
|
+
args: [snap.marketplace, amount]
|
|
5171
|
+
}),
|
|
5172
|
+
value: 0n,
|
|
5173
|
+
fallbackGas: MARKETPLACE_APPROVE_FALLBACK,
|
|
5174
|
+
evmType: "continuum_dao_marketplace_approve",
|
|
5175
|
+
name: "ERC20.approve",
|
|
5176
|
+
extra: { spender: snap.marketplace, amountWei: amount.toString(), token }
|
|
5177
|
+
};
|
|
5178
|
+
}
|
|
5179
|
+
function withApprovals(steps) {
|
|
5180
|
+
return steps.filter((s) => s != null);
|
|
5181
|
+
}
|
|
5182
|
+
function planMarketplaceSteps(input, snap) {
|
|
5183
|
+
const m = snap.marketplace;
|
|
5184
|
+
switch (input.action) {
|
|
5185
|
+
case "createListing": {
|
|
5186
|
+
assertPayment(snap);
|
|
5187
|
+
assertDeadline(snap, input.deadline);
|
|
5188
|
+
if (!same2(snap.owner, snap.executor)) throw new Error("Only the veCTM owner can create a listing.");
|
|
5189
|
+
return withApprovals([
|
|
5190
|
+
nftApproveStep(snap, input.tokenId),
|
|
5191
|
+
{
|
|
5192
|
+
to: m,
|
|
5193
|
+
data: viem.encodeFunctionData({
|
|
5194
|
+
abi: marketplaceAbi,
|
|
5195
|
+
functionName: "createListing",
|
|
5196
|
+
args: [input.tokenId, input.paymentToken, input.askWei, input.deadline]
|
|
5197
|
+
}),
|
|
5198
|
+
value: 0n,
|
|
5199
|
+
fallbackGas: MARKETPLACE_LISTING_FALLBACK,
|
|
5200
|
+
evmType: "continuum_dao_marketplace_create_listing",
|
|
5201
|
+
name: "VotingEscrowMarketplace.createListing",
|
|
5202
|
+
extra: {
|
|
5203
|
+
tokenId: input.tokenId.toString(),
|
|
5204
|
+
paymentToken: input.paymentToken,
|
|
5205
|
+
askWei: input.askWei.toString(),
|
|
5206
|
+
deadline: input.deadline.toString()
|
|
5207
|
+
}
|
|
5208
|
+
}
|
|
5209
|
+
]);
|
|
5210
|
+
}
|
|
5211
|
+
case "delist": {
|
|
5212
|
+
if (!snap.listing || snap.listing.status !== 1) throw new Error("No open listing for this KeyGen.");
|
|
5213
|
+
return [
|
|
5214
|
+
{
|
|
5215
|
+
to: m,
|
|
5216
|
+
data: viem.encodeFunctionData({ abi: marketplaceAbi, functionName: "delist", args: [input.tokenId] }),
|
|
5217
|
+
value: 0n,
|
|
5218
|
+
fallbackGas: MARKETPLACE_LISTING_FALLBACK,
|
|
5219
|
+
evmType: "continuum_dao_marketplace_delist",
|
|
5220
|
+
name: "VotingEscrowMarketplace.delist",
|
|
5221
|
+
extra: { tokenId: input.tokenId.toString() }
|
|
5222
|
+
}
|
|
5223
|
+
];
|
|
5224
|
+
}
|
|
5225
|
+
case "fulfillListing": {
|
|
5226
|
+
assertNotOwn(snap, input.seller, input.tokenId);
|
|
5227
|
+
const listing = snap.listing;
|
|
5228
|
+
if (!listing || !same2(listing.creator, input.seller)) throw new Error("No open listing for this seller.");
|
|
5229
|
+
if (!same2(listing.paymentToken, input.paymentToken) || listing.price !== input.priceWei) {
|
|
5230
|
+
throw new Error("Listing price or payment token changed. Refresh and try again.");
|
|
5231
|
+
}
|
|
5232
|
+
const weth = isWeth(snap, listing.paymentToken);
|
|
5233
|
+
return withApprovals([
|
|
5234
|
+
weth ? null : erc20Approve(snap, listing.paymentToken, listing.price),
|
|
5235
|
+
{
|
|
5236
|
+
to: m,
|
|
5237
|
+
data: viem.encodeFunctionData({
|
|
5238
|
+
abi: marketplaceAbi,
|
|
5239
|
+
functionName: "fulfillListing",
|
|
5240
|
+
args: [input.tokenId, input.seller, listing.paymentToken, listing.price]
|
|
5241
|
+
}),
|
|
5242
|
+
value: weth ? listing.price : 0n,
|
|
5243
|
+
fallbackGas: MARKETPLACE_FULFILL_FALLBACK,
|
|
5244
|
+
evmType: "continuum_dao_marketplace_fulfill_listing",
|
|
5245
|
+
name: "VotingEscrowMarketplace.fulfillListing",
|
|
5246
|
+
extra: {
|
|
5247
|
+
tokenId: input.tokenId.toString(),
|
|
5248
|
+
seller: input.seller,
|
|
5249
|
+
paymentToken: listing.paymentToken,
|
|
5250
|
+
priceWei: listing.price.toString(),
|
|
5251
|
+
recipient: snap.executor
|
|
5252
|
+
}
|
|
5253
|
+
}
|
|
5254
|
+
]);
|
|
5255
|
+
}
|
|
5256
|
+
case "createOffering": {
|
|
5257
|
+
assertNotOwn(snap, void 0, input.tokenId);
|
|
5258
|
+
assertPayment(snap);
|
|
5259
|
+
assertDeadline(snap, input.deadline);
|
|
5260
|
+
const weth = isWeth(snap, input.paymentToken);
|
|
5261
|
+
return withApprovals([
|
|
5262
|
+
erc20Approve(snap, input.paymentToken, input.bidWei),
|
|
5263
|
+
{
|
|
5264
|
+
to: m,
|
|
5265
|
+
data: viem.encodeFunctionData({
|
|
5266
|
+
abi: marketplaceAbi,
|
|
5267
|
+
functionName: "createOffering",
|
|
5268
|
+
args: [input.tokenId, input.paymentToken, input.bidWei, input.deadline]
|
|
5269
|
+
}),
|
|
5270
|
+
value: weth ? input.bidWei : 0n,
|
|
5271
|
+
fallbackGas: MARKETPLACE_OFFERING_FALLBACK,
|
|
5272
|
+
evmType: "continuum_dao_marketplace_create_offering",
|
|
5273
|
+
name: "VotingEscrowMarketplace.createOffering",
|
|
5274
|
+
extra: {
|
|
5275
|
+
tokenId: input.tokenId.toString(),
|
|
5276
|
+
paymentToken: input.paymentToken,
|
|
5277
|
+
bidWei: input.bidWei.toString(),
|
|
5278
|
+
deadline: input.deadline.toString()
|
|
5279
|
+
}
|
|
5280
|
+
}
|
|
5281
|
+
]);
|
|
5282
|
+
}
|
|
5283
|
+
case "rescind": {
|
|
5284
|
+
if (!snap.offering || snap.offering.status !== 1) throw new Error("No open offering for this KeyGen.");
|
|
5285
|
+
return [
|
|
5286
|
+
{
|
|
5287
|
+
to: m,
|
|
5288
|
+
data: viem.encodeFunctionData({ abi: marketplaceAbi, functionName: "rescind", args: [input.tokenId] }),
|
|
5289
|
+
value: 0n,
|
|
5290
|
+
fallbackGas: MARKETPLACE_OFFERING_FALLBACK,
|
|
5291
|
+
evmType: "continuum_dao_marketplace_rescind",
|
|
5292
|
+
name: "VotingEscrowMarketplace.rescind",
|
|
5293
|
+
extra: { tokenId: input.tokenId.toString() }
|
|
5294
|
+
}
|
|
5295
|
+
];
|
|
5296
|
+
}
|
|
5297
|
+
case "fulfillOffering": {
|
|
5298
|
+
assertNotAttached(snap, input.tokenId);
|
|
5299
|
+
if (!same2(snap.owner, snap.executor)) throw new Error("Only the veCTM owner can accept an offering.");
|
|
5300
|
+
const offering = snap.offering;
|
|
5301
|
+
if (!offering || !same2(offering.creator, input.buyer)) throw new Error("No open offering for this buyer.");
|
|
5302
|
+
if (!same2(offering.paymentToken, input.paymentToken) || offering.price !== input.priceWei) {
|
|
5303
|
+
throw new Error("Offering price or payment token changed. Refresh and try again.");
|
|
5304
|
+
}
|
|
5305
|
+
return withApprovals([
|
|
5306
|
+
nftApproveStep(snap, input.tokenId),
|
|
5307
|
+
{
|
|
5308
|
+
to: m,
|
|
5309
|
+
data: viem.encodeFunctionData({
|
|
5310
|
+
abi: marketplaceAbi,
|
|
5311
|
+
functionName: "fulfillOffering",
|
|
5312
|
+
args: [input.tokenId, input.buyer, offering.paymentToken, offering.price]
|
|
5313
|
+
}),
|
|
5314
|
+
value: 0n,
|
|
5315
|
+
fallbackGas: MARKETPLACE_FULFILL_FALLBACK,
|
|
5316
|
+
evmType: "continuum_dao_marketplace_fulfill_offering",
|
|
5317
|
+
name: "VotingEscrowMarketplace.fulfillOffering",
|
|
5318
|
+
extra: {
|
|
5319
|
+
tokenId: input.tokenId.toString(),
|
|
5320
|
+
buyer: input.buyer,
|
|
5321
|
+
paymentToken: offering.paymentToken,
|
|
5322
|
+
priceWei: offering.price.toString()
|
|
5323
|
+
}
|
|
5324
|
+
}
|
|
5325
|
+
]);
|
|
5326
|
+
}
|
|
5327
|
+
case "createAuction": {
|
|
5328
|
+
assertNotAttached(snap, input.tokenId);
|
|
5329
|
+
assertPayment(snap);
|
|
5330
|
+
assertDeadline(snap, input.deadline);
|
|
5331
|
+
if (input.reserveWei <= 0n) throw new Error("Reserve price must be greater than zero.");
|
|
5332
|
+
if (!same2(snap.owner, snap.executor)) throw new Error("Only the veCTM owner can start an auction.");
|
|
5333
|
+
if (snap.executorLiveAuction) throw new Error("A live auction already exists for this token.");
|
|
5334
|
+
return withApprovals([
|
|
5335
|
+
nftApproveStep(snap, input.tokenId),
|
|
5336
|
+
{
|
|
5337
|
+
to: m,
|
|
5338
|
+
data: viem.encodeFunctionData({
|
|
5339
|
+
abi: marketplaceAbi,
|
|
5340
|
+
functionName: "createAuction",
|
|
5341
|
+
args: [input.tokenId, input.paymentToken, input.deadline, input.reserveWei, input.minIncrementWei]
|
|
5342
|
+
}),
|
|
5343
|
+
value: 0n,
|
|
5344
|
+
fallbackGas: MARKETPLACE_AUCTION_CREATE_FALLBACK,
|
|
5345
|
+
evmType: "continuum_dao_marketplace_create_auction",
|
|
5346
|
+
name: "VotingEscrowMarketplace.createAuction",
|
|
5347
|
+
extra: {
|
|
5348
|
+
tokenId: input.tokenId.toString(),
|
|
5349
|
+
paymentToken: input.paymentToken,
|
|
5350
|
+
reserveWei: input.reserveWei.toString(),
|
|
5351
|
+
minIncrementWei: input.minIncrementWei.toString(),
|
|
5352
|
+
deadline: input.deadline.toString()
|
|
5353
|
+
}
|
|
5354
|
+
}
|
|
5355
|
+
]);
|
|
5356
|
+
}
|
|
5357
|
+
case "cancelAuction": {
|
|
5358
|
+
const auction = snap.auction;
|
|
5359
|
+
if (!auction || !same2(auction.seller, snap.executor)) throw new Error("No auction for this KeyGen.");
|
|
5360
|
+
if (auction.status !== 1) throw new Error("Only a pending auction with no bids can be canceled.");
|
|
5361
|
+
return [
|
|
5362
|
+
{
|
|
5363
|
+
to: m,
|
|
5364
|
+
data: viem.encodeFunctionData({ abi: marketplaceAbi, functionName: "cancelAuction", args: [input.tokenId] }),
|
|
5365
|
+
value: 0n,
|
|
5366
|
+
fallbackGas: MARKETPLACE_AUCTION_CREATE_FALLBACK,
|
|
5367
|
+
evmType: "continuum_dao_marketplace_cancel_auction",
|
|
5368
|
+
name: "VotingEscrowMarketplace.cancelAuction",
|
|
5369
|
+
extra: { tokenId: input.tokenId.toString(), recipient: snap.executor }
|
|
5370
|
+
}
|
|
5371
|
+
];
|
|
5372
|
+
}
|
|
5373
|
+
case "auctionBid": {
|
|
5374
|
+
assertNotOwn(snap, input.seller, input.tokenId);
|
|
5375
|
+
const auction = snap.auction;
|
|
5376
|
+
if (!auction || !same2(auction.seller, input.seller)) throw new Error("No live auction for this seller.");
|
|
5377
|
+
if (auction.status !== 1 && auction.status !== 2) throw new Error("This auction is not accepting bids.");
|
|
5378
|
+
if (input.priceWei < auction.reservePrice) throw new Error("Bid is below the reserve price.");
|
|
5379
|
+
if (auction.highestBidder !== viem.zeroAddress && input.priceWei < auction.highestBid + auction.minimumBidIncrement) {
|
|
5380
|
+
throw new Error("Bid is below the highest bid plus the minimum increment.");
|
|
5381
|
+
}
|
|
5382
|
+
const weth = isWeth(snap, auction.paymentToken);
|
|
5383
|
+
return withApprovals([
|
|
5384
|
+
weth ? null : erc20Approve(snap, auction.paymentToken, input.priceWei),
|
|
5385
|
+
{
|
|
5386
|
+
to: m,
|
|
5387
|
+
data: viem.encodeFunctionData({
|
|
5388
|
+
abi: marketplaceAbi,
|
|
5389
|
+
functionName: "auctionBid",
|
|
5390
|
+
args: [input.tokenId, input.seller, input.priceWei]
|
|
5391
|
+
}),
|
|
5392
|
+
value: weth ? input.priceWei : 0n,
|
|
5393
|
+
fallbackGas: MARKETPLACE_BID_FALLBACK,
|
|
5394
|
+
evmType: "continuum_dao_marketplace_auction_bid",
|
|
5395
|
+
name: "VotingEscrowMarketplace.auctionBid",
|
|
5396
|
+
extra: {
|
|
5397
|
+
tokenId: input.tokenId.toString(),
|
|
5398
|
+
seller: input.seller,
|
|
5399
|
+
priceWei: input.priceWei.toString(),
|
|
5400
|
+
paymentToken: auction.paymentToken
|
|
5401
|
+
}
|
|
5402
|
+
}
|
|
5403
|
+
]);
|
|
5404
|
+
}
|
|
5405
|
+
case "settleAuction": {
|
|
5406
|
+
const auction = snap.auction;
|
|
5407
|
+
if (!auction || !same2(auction.seller, input.seller)) throw new Error("Auction not found.");
|
|
5408
|
+
const derived = auction.status === 2 && snap.now >= auction.deadline ? 3 : auction.status === 1 && snap.now >= auction.deadline ? 6 : auction.status;
|
|
5409
|
+
if (derived !== 3 && derived !== 6) throw new Error("This auction is not ready to settle.");
|
|
5410
|
+
const winner = auction.highestBidder;
|
|
5411
|
+
return [
|
|
5412
|
+
{
|
|
5413
|
+
to: m,
|
|
5414
|
+
data: viem.encodeFunctionData({
|
|
5415
|
+
abi: marketplaceAbi,
|
|
5416
|
+
functionName: "settleAuction",
|
|
5417
|
+
args: [input.tokenId, input.seller]
|
|
5418
|
+
}),
|
|
5419
|
+
value: 0n,
|
|
5420
|
+
fallbackGas: MARKETPLACE_SETTLE_FALLBACK,
|
|
5421
|
+
evmType: "continuum_dao_marketplace_settle_auction",
|
|
5422
|
+
name: "VotingEscrowMarketplace.settleAuction",
|
|
5423
|
+
extra: {
|
|
5424
|
+
tokenId: input.tokenId.toString(),
|
|
5425
|
+
seller: input.seller,
|
|
5426
|
+
highestBidder: winner,
|
|
5427
|
+
recipient: derived === 3 ? winner : input.seller
|
|
5428
|
+
}
|
|
5429
|
+
}
|
|
5430
|
+
];
|
|
5431
|
+
}
|
|
5432
|
+
default:
|
|
5433
|
+
throw new Error("Unknown marketplace action.");
|
|
5434
|
+
}
|
|
5435
|
+
}
|
|
5436
|
+
|
|
5437
|
+
// src/protocols/evm/continuum-dao/marketplaceChain.ts
|
|
5438
|
+
init_defiEvmClient();
|
|
5439
|
+
init_constants();
|
|
5440
|
+
function marketplacePublicClient(chainId, rpcUrl) {
|
|
5441
|
+
const ch = viem.defineChain({
|
|
5442
|
+
id: chainId,
|
|
5443
|
+
name: "Linea",
|
|
5444
|
+
nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" },
|
|
5445
|
+
rpcUrls: { default: { http: [rpcUrl] } }
|
|
5446
|
+
});
|
|
5447
|
+
return viem.createPublicClient({ chain: ch, transport: defiEvmTransport(rpcUrl) });
|
|
5448
|
+
}
|
|
5449
|
+
var KNOWN_PAYMENT_TOKENS = [
|
|
5450
|
+
{ address: viem.getAddress(exports.CTM_TOKEN_ADDRESS), symbol: "CTM", decimals: 18 },
|
|
5451
|
+
{ address: exports.MARKETPLACE_WETH_LINEA_ADDRESS, symbol: "WETH", decimals: 18 },
|
|
5452
|
+
{ address: exports.MARKETPLACE_USDC_LINEA_ADDRESS, symbol: "USDC", decimals: 6 }
|
|
5453
|
+
];
|
|
5454
|
+
function calculateMarketplaceFee(price, lockedAmount, limits, rates) {
|
|
5455
|
+
for (let i = 0; i < 5; i++) {
|
|
5456
|
+
const limit = limits[i] ?? 0n;
|
|
5457
|
+
if (lockedAmount >= limit) {
|
|
5458
|
+
const rateBps = rates[i] ?? 0n;
|
|
5459
|
+
const fee = price * rateBps / 10000n;
|
|
5460
|
+
return {
|
|
5461
|
+
tier: FEE_TIER_NAMES[i] ?? "Blue",
|
|
5462
|
+
tierIndex: i,
|
|
5463
|
+
limit,
|
|
5464
|
+
rateBps,
|
|
5465
|
+
fee,
|
|
5466
|
+
net: price - fee
|
|
5467
|
+
};
|
|
5468
|
+
}
|
|
5469
|
+
}
|
|
5470
|
+
return null;
|
|
5471
|
+
}
|
|
5472
|
+
async function readMarketplaceConfigFromChain(args) {
|
|
5473
|
+
const marketplace = args.marketplace ?? exports.VOTING_ESCROW_MARKETPLACE_LINEA_ADDRESS;
|
|
5474
|
+
const client = marketplacePublicClient(args.chainId, args.rpcUrl);
|
|
5475
|
+
const [weth, ve, gov, np, minimumDuration, maximumDuration] = await Promise.all([
|
|
5476
|
+
client.readContract({ address: marketplace, abi: marketplaceAbi, functionName: "weth" }),
|
|
5477
|
+
client.readContract({ address: marketplace, abi: marketplaceAbi, functionName: "ve" }),
|
|
5478
|
+
client.readContract({ address: marketplace, abi: marketplaceAbi, functionName: "gov" }),
|
|
5479
|
+
client.readContract({ address: marketplace, abi: marketplaceAbi, functionName: "np" }),
|
|
5480
|
+
client.readContract({ address: marketplace, abi: marketplaceAbi, functionName: "minimumDuration" }),
|
|
5481
|
+
client.readContract({ address: marketplace, abi: marketplaceAbi, functionName: "maximumDuration" })
|
|
5482
|
+
]);
|
|
5483
|
+
const feeLimits = [];
|
|
5484
|
+
const feeRates = [];
|
|
5485
|
+
for (let i = 0; i < 5; i++) {
|
|
5486
|
+
const [limit, rate] = await Promise.all([
|
|
5487
|
+
client.readContract({
|
|
5488
|
+
address: marketplace,
|
|
5489
|
+
abi: marketplaceAbi,
|
|
5490
|
+
functionName: "feeLimitByTier",
|
|
5491
|
+
args: [i]
|
|
5492
|
+
}),
|
|
5493
|
+
client.readContract({
|
|
5494
|
+
address: marketplace,
|
|
5495
|
+
abi: marketplaceAbi,
|
|
5496
|
+
functionName: "feeRateByTier",
|
|
5497
|
+
args: [i]
|
|
5498
|
+
})
|
|
5499
|
+
]);
|
|
5500
|
+
feeLimits.push(limit);
|
|
5501
|
+
feeRates.push(rate);
|
|
5502
|
+
}
|
|
5503
|
+
const paymentTokens = [];
|
|
5504
|
+
for (const token of KNOWN_PAYMENT_TOKENS) {
|
|
5505
|
+
let isValid = false;
|
|
5506
|
+
try {
|
|
5507
|
+
isValid = await client.readContract({
|
|
5508
|
+
address: marketplace,
|
|
5509
|
+
abi: marketplaceAbi,
|
|
5510
|
+
functionName: "isValidPaymentToken",
|
|
5511
|
+
args: [token.address]
|
|
5512
|
+
});
|
|
5513
|
+
} catch {
|
|
5514
|
+
isValid = false;
|
|
5515
|
+
}
|
|
5516
|
+
if (isValid) paymentTokens.push({ ...token, address: token.address, isValid: true });
|
|
5517
|
+
}
|
|
5518
|
+
return {
|
|
5519
|
+
chainId: args.chainId,
|
|
5520
|
+
marketplace,
|
|
5521
|
+
ve,
|
|
5522
|
+
gov,
|
|
5523
|
+
np,
|
|
5524
|
+
weth,
|
|
5525
|
+
minimumDuration: minimumDuration.toString(),
|
|
5526
|
+
maximumDuration: maximumDuration.toString(),
|
|
5527
|
+
feeLimits: feeLimits.map((n) => n.toString()),
|
|
5528
|
+
feeRates: feeRates.map((n) => n.toString()),
|
|
5529
|
+
feeTiers: FEE_TIER_NAMES.map((name, index) => ({
|
|
5530
|
+
name,
|
|
5531
|
+
index,
|
|
5532
|
+
limit: feeLimits[index].toString(),
|
|
5533
|
+
rateBps: feeRates[index].toString()
|
|
5534
|
+
})),
|
|
5535
|
+
paymentTokens,
|
|
5536
|
+
source: "logs"
|
|
5537
|
+
};
|
|
5538
|
+
}
|
|
5539
|
+
async function readMarketplaceFeePreviewFromChain(args) {
|
|
5540
|
+
const marketplace = args.marketplace ?? exports.VOTING_ESCROW_MARKETPLACE_LINEA_ADDRESS;
|
|
5541
|
+
const ve = args.votingEscrow ?? exports.VOTING_ESCROW_LINEA_ADDRESS;
|
|
5542
|
+
const client = marketplacePublicClient(args.chainId, args.rpcUrl);
|
|
5543
|
+
const locked = await client.readContract({
|
|
5544
|
+
address: ve,
|
|
5545
|
+
abi: marketplaceReadAbi,
|
|
5546
|
+
functionName: "locked",
|
|
5547
|
+
args: [args.tokenId]
|
|
5548
|
+
});
|
|
5549
|
+
const lockedAmount = BigInt(locked[0]);
|
|
5550
|
+
const limits = [];
|
|
5551
|
+
const rates = [];
|
|
5552
|
+
for (let i = 0; i < 5; i++) {
|
|
5553
|
+
limits.push(
|
|
5554
|
+
await client.readContract({
|
|
5555
|
+
address: marketplace,
|
|
5556
|
+
abi: marketplaceAbi,
|
|
5557
|
+
functionName: "feeLimitByTier",
|
|
5558
|
+
args: [i]
|
|
5559
|
+
})
|
|
5560
|
+
);
|
|
5561
|
+
rates.push(
|
|
5562
|
+
await client.readContract({
|
|
5563
|
+
address: marketplace,
|
|
5564
|
+
abi: marketplaceAbi,
|
|
5565
|
+
functionName: "feeRateByTier",
|
|
5566
|
+
args: [i]
|
|
5567
|
+
})
|
|
5568
|
+
);
|
|
5569
|
+
}
|
|
5570
|
+
const fee = calculateMarketplaceFee(args.price, lockedAmount < 0n ? 0n : lockedAmount, limits, rates);
|
|
5571
|
+
if (!fee) throw new Error("Locked CTM is below the minimum fee tier.");
|
|
5572
|
+
return {
|
|
5573
|
+
tokenId: args.tokenId.toString(),
|
|
5574
|
+
lockedAmount: (lockedAmount < 0n ? 0n : lockedAmount).toString(),
|
|
5575
|
+
tier: fee.tier,
|
|
5576
|
+
tierIndex: fee.tierIndex,
|
|
5577
|
+
limit: fee.limit.toString(),
|
|
5578
|
+
rateBps: fee.rateBps.toString(),
|
|
5579
|
+
price: args.price.toString(),
|
|
5580
|
+
fee: fee.fee.toString(),
|
|
5581
|
+
net: fee.net.toString(),
|
|
5582
|
+
source: "logs"
|
|
5583
|
+
};
|
|
5584
|
+
}
|
|
5585
|
+
async function readOrder(client, marketplace, tokenId, index, kind) {
|
|
5586
|
+
if (index === 0n) return null;
|
|
5587
|
+
const row = kind === "listing" ? await client.readContract({
|
|
5588
|
+
address: marketplace,
|
|
5589
|
+
abi: marketplaceAbi,
|
|
5590
|
+
functionName: "listingsByToken",
|
|
5591
|
+
args: [tokenId, index]
|
|
5592
|
+
}) : await client.readContract({
|
|
5593
|
+
address: marketplace,
|
|
5594
|
+
abi: marketplaceAbi,
|
|
5595
|
+
functionName: "offeringsByToken",
|
|
5596
|
+
args: [tokenId, index]
|
|
5597
|
+
});
|
|
5598
|
+
return {
|
|
5599
|
+
price: row[0],
|
|
5600
|
+
deadline: row[1],
|
|
5601
|
+
snapshotAmount: row[2],
|
|
5602
|
+
snapshotEnd: row[3],
|
|
5603
|
+
creator: row[4],
|
|
5604
|
+
paymentToken: row[5],
|
|
5605
|
+
status: Number(row[6])
|
|
5606
|
+
};
|
|
5607
|
+
}
|
|
5608
|
+
async function readAuction(client, marketplace, tokenId, index) {
|
|
5609
|
+
if (index === 0n) return null;
|
|
5610
|
+
const row = await client.readContract({
|
|
5611
|
+
address: marketplace,
|
|
5612
|
+
abi: marketplaceAbi,
|
|
5613
|
+
functionName: "auctionsByToken",
|
|
5614
|
+
args: [tokenId, index]
|
|
5615
|
+
});
|
|
5616
|
+
return {
|
|
5617
|
+
reservePrice: row[0],
|
|
5618
|
+
minimumBidIncrement: row[1],
|
|
5619
|
+
deadline: row[2],
|
|
5620
|
+
seller: row[3],
|
|
5621
|
+
paymentToken: row[4],
|
|
5622
|
+
highestBidder: row[5],
|
|
5623
|
+
highestBid: row[6],
|
|
5624
|
+
status: Number(row[7])
|
|
5625
|
+
};
|
|
5626
|
+
}
|
|
5627
|
+
async function loadMarketplacePlanSnapshot(args) {
|
|
5628
|
+
const marketplace = exports.VOTING_ESCROW_MARKETPLACE_LINEA_ADDRESS;
|
|
5629
|
+
const client = marketplacePublicClient(args.chainId, args.rpcUrl);
|
|
5630
|
+
const [weth, ve, np, minimumDuration, maximumDuration, block] = await Promise.all([
|
|
5631
|
+
client.readContract({ address: marketplace, abi: marketplaceAbi, functionName: "weth" }),
|
|
5632
|
+
client.readContract({ address: marketplace, abi: marketplaceAbi, functionName: "ve" }),
|
|
5633
|
+
client.readContract({ address: marketplace, abi: marketplaceAbi, functionName: "np" }),
|
|
5634
|
+
client.readContract({ address: marketplace, abi: marketplaceAbi, functionName: "minimumDuration" }),
|
|
5635
|
+
client.readContract({ address: marketplace, abi: marketplaceAbi, functionName: "maximumDuration" }),
|
|
5636
|
+
client.getBlock({ blockTag: "latest" })
|
|
5637
|
+
]);
|
|
5638
|
+
let owner = viem.zeroAddress;
|
|
5639
|
+
try {
|
|
5640
|
+
owner = await client.readContract({
|
|
5641
|
+
address: ve,
|
|
5642
|
+
abi: marketplaceReadAbi,
|
|
5643
|
+
functionName: "ownerOf",
|
|
5644
|
+
args: [args.tokenId]
|
|
5645
|
+
});
|
|
5646
|
+
} catch {
|
|
5647
|
+
owner = viem.zeroAddress;
|
|
5648
|
+
}
|
|
5649
|
+
const [approved, approvedForAll, attachedKeyGen, listingIndex, offeringIndex, auctionIndex] = await Promise.all([
|
|
5650
|
+
client.readContract({ address: ve, abi: marketplaceReadAbi, functionName: "getApproved", args: [args.tokenId] }).catch(() => viem.zeroAddress),
|
|
5651
|
+
owner === viem.zeroAddress ? Promise.resolve(false) : client.readContract({
|
|
5652
|
+
address: ve,
|
|
5653
|
+
abi: marketplaceReadAbi,
|
|
5654
|
+
functionName: "isApprovedForAll",
|
|
5655
|
+
args: [owner, marketplace]
|
|
5656
|
+
}).catch(() => false),
|
|
5657
|
+
client.readContract({ address: np, abi: marketplaceReadAbi, functionName: "attachedKeyGen", args: [args.tokenId] }).catch(() => viem.zeroAddress),
|
|
5658
|
+
client.readContract({
|
|
5659
|
+
address: marketplace,
|
|
5660
|
+
abi: marketplaceAbi,
|
|
5661
|
+
functionName: "listingIndexByTokenSeller",
|
|
5662
|
+
args: [args.tokenId, args.seller ?? args.executor]
|
|
5663
|
+
}),
|
|
5664
|
+
client.readContract({
|
|
5665
|
+
address: marketplace,
|
|
5666
|
+
abi: marketplaceAbi,
|
|
5667
|
+
functionName: "offeringIndexByTokenBuyer",
|
|
5668
|
+
args: [args.tokenId, args.buyer ?? args.executor]
|
|
5669
|
+
}),
|
|
5670
|
+
client.readContract({
|
|
5671
|
+
address: marketplace,
|
|
5672
|
+
abi: marketplaceAbi,
|
|
5673
|
+
functionName: "auctionIndexByTokenSeller",
|
|
5674
|
+
args: [args.tokenId, args.seller ?? args.executor]
|
|
5675
|
+
})
|
|
5676
|
+
]);
|
|
5677
|
+
const [listing, offering, auction, executorListingIndex, executorAuctionIndex] = await Promise.all([
|
|
5678
|
+
readOrder(client, marketplace, args.tokenId, listingIndex, "listing"),
|
|
5679
|
+
readOrder(client, marketplace, args.tokenId, offeringIndex, "offering"),
|
|
5680
|
+
readAuction(client, marketplace, args.tokenId, auctionIndex),
|
|
5681
|
+
args.seller && args.seller !== args.executor ? client.readContract({
|
|
5682
|
+
address: marketplace,
|
|
5683
|
+
abi: marketplaceAbi,
|
|
5684
|
+
functionName: "listingIndexByTokenSeller",
|
|
5685
|
+
args: [args.tokenId, args.executor]
|
|
5686
|
+
}) : Promise.resolve(0n),
|
|
5687
|
+
args.seller && args.seller !== args.executor ? client.readContract({
|
|
5688
|
+
address: marketplace,
|
|
5689
|
+
abi: marketplaceAbi,
|
|
5690
|
+
functionName: "auctionIndexByTokenSeller",
|
|
5691
|
+
args: [args.tokenId, args.executor]
|
|
5692
|
+
}) : Promise.resolve(auctionIndex)
|
|
5693
|
+
]);
|
|
5694
|
+
const executorAuction = executorAuctionIndex === auctionIndex ? auction : await readAuction(client, marketplace, args.tokenId, executorAuctionIndex);
|
|
5695
|
+
const liveAuction = executorAuction != null && (executorAuction.status === 1 || executorAuction.status === 2 || executorAuction.status === 3) && executorAuction.seller.toLowerCase() === args.executor.toLowerCase();
|
|
5696
|
+
let executorOpenListing = false;
|
|
5697
|
+
if (executorListingIndex > 0n) {
|
|
5698
|
+
const row = await readOrder(client, marketplace, args.tokenId, executorListingIndex, "listing");
|
|
5699
|
+
executorOpenListing = row?.status === 1;
|
|
5700
|
+
} else if (!args.seller || args.seller === args.executor) {
|
|
5701
|
+
executorOpenListing = listing?.status === 1 && listing.creator.toLowerCase() === args.executor.toLowerCase();
|
|
5702
|
+
}
|
|
5703
|
+
const paymentToken = args.paymentToken ?? listing?.paymentToken ?? offering?.paymentToken ?? auction?.paymentToken;
|
|
5704
|
+
let paymentTokenValid = true;
|
|
5705
|
+
if (paymentToken) {
|
|
5706
|
+
paymentTokenValid = await client.readContract({
|
|
5707
|
+
address: marketplace,
|
|
5708
|
+
abi: marketplaceAbi,
|
|
5709
|
+
functionName: "isValidPaymentToken",
|
|
5710
|
+
args: [paymentToken]
|
|
5711
|
+
});
|
|
5712
|
+
}
|
|
5713
|
+
const spendToken = paymentToken ?? viem.zeroAddress;
|
|
5714
|
+
const spendFrom = args.buyer && args.buyer !== args.executor ? args.buyer : args.executor;
|
|
5715
|
+
let allowance = 0n;
|
|
5716
|
+
if (spendToken !== viem.zeroAddress && spendToken.toLowerCase() !== weth.toLowerCase()) {
|
|
5717
|
+
allowance = await client.readContract({
|
|
5718
|
+
address: spendToken,
|
|
5719
|
+
abi: marketplaceReadAbi,
|
|
5720
|
+
functionName: "allowance",
|
|
5721
|
+
args: [spendFrom, marketplace]
|
|
5722
|
+
}).catch(() => 0n);
|
|
5723
|
+
} else if (spendToken.toLowerCase() === weth.toLowerCase()) {
|
|
5724
|
+
allowance = await client.readContract({
|
|
5725
|
+
address: spendToken,
|
|
5726
|
+
abi: marketplaceReadAbi,
|
|
5727
|
+
functionName: "allowance",
|
|
5728
|
+
args: [args.executor, marketplace]
|
|
5729
|
+
}).catch(() => 0n);
|
|
5730
|
+
}
|
|
5731
|
+
return {
|
|
5732
|
+
marketplace,
|
|
5733
|
+
votingEscrow: ve,
|
|
5734
|
+
weth,
|
|
5735
|
+
now: block.timestamp,
|
|
5736
|
+
minimumDuration,
|
|
5737
|
+
maximumDuration,
|
|
5738
|
+
executor: args.executor,
|
|
5739
|
+
owner,
|
|
5740
|
+
nftApproved: approvedForAll || approved !== viem.zeroAddress && approved.toLowerCase() === marketplace.toLowerCase(),
|
|
5741
|
+
allowance,
|
|
5742
|
+
attachedKeyGen,
|
|
5743
|
+
paymentTokenValid,
|
|
5744
|
+
executorOpenListing,
|
|
5745
|
+
executorLiveAuction: liveAuction,
|
|
5746
|
+
listing: listing && listing.status === 1 ? listing : listing,
|
|
5747
|
+
offering: offering && offering.status === 1 ? offering : offering,
|
|
5748
|
+
auction
|
|
5749
|
+
};
|
|
5750
|
+
}
|
|
5751
|
+
init_constants();
|
|
5752
|
+
var memoryCache = /* @__PURE__ */ new Map();
|
|
5753
|
+
function emptyMarketplaceIndexCache() {
|
|
5754
|
+
return { lastScannedBlock: "0", listings: [], offerings: [], auctions: [] };
|
|
5755
|
+
}
|
|
5756
|
+
function getMarketplaceIndexMemoryCache(chainId) {
|
|
5757
|
+
return memoryCache.get(chainId) ?? null;
|
|
5758
|
+
}
|
|
5759
|
+
function setMarketplaceIndexMemoryCache(chainId, cache) {
|
|
5760
|
+
memoryCache.set(chainId, cache);
|
|
5761
|
+
}
|
|
5762
|
+
function arg(args, key, index) {
|
|
5763
|
+
const value = args[key] ?? args[index];
|
|
5764
|
+
if (typeof value === "bigint") return value.toString();
|
|
5765
|
+
return String(value ?? "");
|
|
5766
|
+
}
|
|
5767
|
+
function toFoldEvent(log, timestamp) {
|
|
5768
|
+
try {
|
|
5769
|
+
const decoded = viem.decodeEventLog({
|
|
5770
|
+
abi: marketplaceAbi,
|
|
5771
|
+
data: log.data,
|
|
5772
|
+
topics: log.topics
|
|
5773
|
+
});
|
|
5774
|
+
const args = decoded.args;
|
|
5775
|
+
const ref = {
|
|
5776
|
+
tx: log.transactionHash ?? "",
|
|
5777
|
+
block: log.blockNumber != null ? log.blockNumber.toString() : "0",
|
|
5778
|
+
logIndex: log.logIndex ?? 0,
|
|
5779
|
+
timestamp
|
|
5780
|
+
};
|
|
5781
|
+
switch (decoded.eventName) {
|
|
5782
|
+
case "ListingCreated":
|
|
5783
|
+
return {
|
|
5784
|
+
name: "ListingCreated",
|
|
5785
|
+
tokenId: arg(args, "_tokenId", 0),
|
|
5786
|
+
actor: arg(args, "_listedBy", 1),
|
|
5787
|
+
paymentToken: arg(args, "_paymentToken", 2),
|
|
5788
|
+
amount: arg(args, "_ask", 3),
|
|
5789
|
+
deadline: arg(args, "_deadline", 4),
|
|
5790
|
+
...ref
|
|
5791
|
+
};
|
|
5792
|
+
case "OfferingCreated":
|
|
5793
|
+
return {
|
|
5794
|
+
name: "OfferingCreated",
|
|
5795
|
+
tokenId: arg(args, "_tokenId", 0),
|
|
5796
|
+
actor: arg(args, "_offeredBy", 1),
|
|
5797
|
+
paymentToken: arg(args, "_paymentToken", 2),
|
|
5798
|
+
amount: arg(args, "_bid", 3),
|
|
5799
|
+
deadline: arg(args, "_deadline", 4),
|
|
5800
|
+
...ref
|
|
5801
|
+
};
|
|
5802
|
+
case "ListingFulfilled":
|
|
5803
|
+
return {
|
|
5804
|
+
name: "ListingFulfilled",
|
|
5805
|
+
tokenId: arg(args, "_tokenId", 0),
|
|
5806
|
+
buyer: arg(args, "_buyer", 1),
|
|
5807
|
+
seller: arg(args, "_seller", 2),
|
|
5808
|
+
price: arg(args, "_ask", 3),
|
|
5809
|
+
net: arg(args, "_netPrice", 4),
|
|
5810
|
+
fee: arg(args, "_fee", 5),
|
|
5811
|
+
...ref
|
|
5812
|
+
};
|
|
5813
|
+
case "OfferingFulfilled":
|
|
5814
|
+
return {
|
|
5815
|
+
name: "OfferingFulfilled",
|
|
5816
|
+
tokenId: arg(args, "_tokenId", 0),
|
|
5817
|
+
buyer: arg(args, "_buyer", 1),
|
|
5818
|
+
seller: arg(args, "_seller", 2),
|
|
5819
|
+
price: arg(args, "_bid", 3),
|
|
5820
|
+
net: arg(args, "_netPrice", 4),
|
|
5821
|
+
fee: arg(args, "_fee", 5),
|
|
5822
|
+
...ref
|
|
5823
|
+
};
|
|
5824
|
+
case "Delisted":
|
|
5825
|
+
return { name: "Delisted", tokenId: arg(args, "_tokenId", 0), actor: arg(args, "_seller", 1), ...ref };
|
|
5826
|
+
case "Rescinded":
|
|
5827
|
+
return { name: "Rescinded", tokenId: arg(args, "_tokenId", 0), actor: arg(args, "_buyer", 1), ...ref };
|
|
5828
|
+
case "AuctionCreated":
|
|
5829
|
+
return {
|
|
5830
|
+
name: "AuctionCreated",
|
|
5831
|
+
tokenId: arg(args, "_tokenId", 0),
|
|
5832
|
+
actor: arg(args, "_createdBy", 1),
|
|
5833
|
+
paymentToken: arg(args, "_paymentToken", 2),
|
|
5834
|
+
amount: arg(args, "_reservePrice", 3),
|
|
5835
|
+
minIncrement: arg(args, "_minimumBidIncrement", 4),
|
|
5836
|
+
deadline: arg(args, "_deadline", 5),
|
|
5837
|
+
...ref
|
|
5838
|
+
};
|
|
5839
|
+
case "AuctionCanceled":
|
|
5840
|
+
return { name: "AuctionCanceled", tokenId: arg(args, "_tokenId", 0), actor: arg(args, "_seller", 1), ...ref };
|
|
5841
|
+
case "AuctionBid":
|
|
5842
|
+
return {
|
|
5843
|
+
name: "AuctionBid",
|
|
5844
|
+
tokenId: arg(args, "_tokenId", 0),
|
|
5845
|
+
seller: arg(args, "_seller", 1),
|
|
5846
|
+
buyer: arg(args, "_buyer", 2),
|
|
5847
|
+
price: arg(args, "_price", 3),
|
|
5848
|
+
...ref
|
|
5849
|
+
};
|
|
5850
|
+
case "AuctionSettled":
|
|
5851
|
+
return {
|
|
5852
|
+
name: "AuctionSettled",
|
|
5853
|
+
tokenId: arg(args, "_tokenId", 0),
|
|
5854
|
+
seller: arg(args, "_seller", 1),
|
|
5855
|
+
finalStatus: Number(args._finalStatus ?? args[2] ?? 0),
|
|
5856
|
+
...ref
|
|
5857
|
+
};
|
|
5858
|
+
case "AuctionSuccessful":
|
|
5859
|
+
return {
|
|
5860
|
+
name: "AuctionSuccessful",
|
|
5861
|
+
tokenId: arg(args, "_tokenId", 0),
|
|
5862
|
+
seller: arg(args, "_seller", 1),
|
|
5863
|
+
buyer: arg(args, "_buyer", 2),
|
|
5864
|
+
price: arg(args, "_price", 3),
|
|
5865
|
+
fee: arg(args, "_fee", 4),
|
|
5866
|
+
net: arg(args, "_net", 5),
|
|
5867
|
+
...ref
|
|
5868
|
+
};
|
|
5869
|
+
default:
|
|
5870
|
+
return null;
|
|
5871
|
+
}
|
|
5872
|
+
} catch {
|
|
5873
|
+
return null;
|
|
5874
|
+
}
|
|
5875
|
+
}
|
|
5876
|
+
async function getLogsChunked(args) {
|
|
5877
|
+
const logs = [];
|
|
5878
|
+
let chunk = 5000n;
|
|
5879
|
+
let start = args.fromBlock;
|
|
5880
|
+
while (start <= args.toBlock) {
|
|
5881
|
+
const end = start + chunk - 1n > args.toBlock ? args.toBlock : start + chunk - 1n;
|
|
5882
|
+
try {
|
|
5883
|
+
const part = await args.client.getLogs({
|
|
5884
|
+
address: args.address,
|
|
5885
|
+
fromBlock: start,
|
|
5886
|
+
toBlock: end
|
|
5887
|
+
});
|
|
5888
|
+
logs.push(...part);
|
|
5889
|
+
args.onProgress?.(end, args.toBlock);
|
|
5890
|
+
start = end + 1n;
|
|
5891
|
+
} catch (err) {
|
|
5892
|
+
if (chunk <= 200n) throw err;
|
|
5893
|
+
chunk = chunk / 2n < 200n ? 200n : chunk / 2n;
|
|
5894
|
+
}
|
|
5895
|
+
}
|
|
5896
|
+
return logs;
|
|
5897
|
+
}
|
|
5898
|
+
async function scanMarketplaceLogs(args) {
|
|
5899
|
+
const client = marketplacePublicClient(args.chainId, args.rpcUrl);
|
|
5900
|
+
const head = await client.getBlockNumber();
|
|
5901
|
+
const prior = args.cache ?? getMarketplaceIndexMemoryCache(args.chainId) ?? emptyMarketplaceIndexCache();
|
|
5902
|
+
const scanned = BigInt(prior.lastScannedBlock || "0");
|
|
5903
|
+
const fromBlock = scanned > 0n ? scanned + 1n : exports.VOTING_ESCROW_MARKETPLACE_START_BLOCK;
|
|
5904
|
+
if (fromBlock > head) {
|
|
5905
|
+
const now2 = Number((await client.getBlock({ blockTag: "latest" })).timestamp);
|
|
5906
|
+
const derived2 = applyDerivedStatuses(
|
|
5907
|
+
{ listings: prior.listings, offerings: prior.offerings, auctions: prior.auctions },
|
|
5908
|
+
now2
|
|
5909
|
+
);
|
|
5910
|
+
const cache2 = { lastScannedBlock: head.toString(), ...derived2 };
|
|
5911
|
+
setMarketplaceIndexMemoryCache(args.chainId, cache2);
|
|
5912
|
+
return cache2;
|
|
5913
|
+
}
|
|
5914
|
+
const logs = await getLogsChunked({
|
|
5915
|
+
client,
|
|
5916
|
+
address: exports.VOTING_ESCROW_MARKETPLACE_LINEA_ADDRESS,
|
|
5917
|
+
fromBlock,
|
|
5918
|
+
toBlock: head,
|
|
5919
|
+
onProgress: args.onProgress
|
|
5920
|
+
});
|
|
5921
|
+
const events = logs.map((log) => toFoldEvent(log)).filter((ev) => ev != null);
|
|
5922
|
+
const folded = foldMarketplaceEvents(events, {
|
|
5923
|
+
listings: prior.listings,
|
|
5924
|
+
offerings: prior.offerings,
|
|
5925
|
+
auctions: prior.auctions
|
|
5926
|
+
});
|
|
5927
|
+
const now = Number((await client.getBlock({ blockTag: "latest" })).timestamp);
|
|
5928
|
+
const derived = applyDerivedStatuses(folded, now);
|
|
5929
|
+
const cache = { lastScannedBlock: head.toString(), ...derived };
|
|
5930
|
+
setMarketplaceIndexMemoryCache(args.chainId, cache);
|
|
5931
|
+
return cache;
|
|
5932
|
+
}
|
|
5933
|
+
|
|
5934
|
+
// src/protocols/evm/continuum-dao/marketplaceCatalog.ts
|
|
5935
|
+
init_constants();
|
|
5936
|
+
function apiBase(args) {
|
|
5937
|
+
return (args.apiBase ?? exports.CONTINUUM_DAO_MARKETPLACE_API).replace(/\/$/, "");
|
|
5938
|
+
}
|
|
5939
|
+
function isOffline(status) {
|
|
5940
|
+
if (status == null || status === 0 || status >= 500) return true;
|
|
5941
|
+
return false;
|
|
5942
|
+
}
|
|
5943
|
+
async function getJson(url) {
|
|
5944
|
+
try {
|
|
5945
|
+
const res = await fetch(url);
|
|
5946
|
+
if (!res.ok) {
|
|
5947
|
+
const text = await res.text().catch(() => "");
|
|
5948
|
+
return { ok: false, status: res.status, error: new Error(`${url}: ${res.status} ${text}`.trim()) };
|
|
5949
|
+
}
|
|
5950
|
+
return { ok: true, body: await res.json() };
|
|
5951
|
+
} catch (err) {
|
|
5952
|
+
return { ok: false, status: 0, error: err instanceof Error ? err : new Error(String(err)) };
|
|
5953
|
+
}
|
|
5954
|
+
}
|
|
5955
|
+
function qs(params) {
|
|
5956
|
+
const search = new URLSearchParams();
|
|
5957
|
+
for (const [key, value] of Object.entries(params)) {
|
|
5958
|
+
if (value === void 0 || value === "") continue;
|
|
5959
|
+
search.set(key, String(value));
|
|
5960
|
+
}
|
|
5961
|
+
const encoded = search.toString();
|
|
5962
|
+
return encoded ? `?${encoded}` : "";
|
|
5963
|
+
}
|
|
5964
|
+
async function logsBook(args) {
|
|
5965
|
+
if (!args.rpcUrl?.trim()) throw new Error("Linea RPC is required to index the marketplace while the API is offline.");
|
|
5966
|
+
return scanMarketplaceLogs({
|
|
5967
|
+
chainId: args.chainId ?? exports.CONTINUUM_DAO_LINEA_CHAIN_ID,
|
|
5968
|
+
rpcUrl: args.rpcUrl.trim(),
|
|
5969
|
+
cache: args.cache,
|
|
5970
|
+
onProgress: args.onProgress
|
|
5971
|
+
});
|
|
5972
|
+
}
|
|
5973
|
+
function matchOrder(row, args, includeInactive) {
|
|
5974
|
+
if (!includeInactive && !isOpenOrder(row)) return false;
|
|
5975
|
+
if (args.tokenId && row.tokenId !== args.tokenId) return false;
|
|
5976
|
+
if (args.paymentToken && row.paymentToken.toLowerCase() !== args.paymentToken.toLowerCase()) return false;
|
|
5977
|
+
if (args.creator && row.creator.toLowerCase() !== args.creator.toLowerCase()) return false;
|
|
5978
|
+
if (args.seller && (row.seller ?? row.creator).toLowerCase() !== args.seller.toLowerCase()) return false;
|
|
5979
|
+
return true;
|
|
5980
|
+
}
|
|
5981
|
+
function matchAuction(row, args, includeInactive) {
|
|
5982
|
+
if (!includeInactive && !isLiveAuctionStatus(row.derivedStatus)) return false;
|
|
5983
|
+
if (args.tokenId && row.tokenId !== args.tokenId) return false;
|
|
5984
|
+
if (args.paymentToken && row.paymentToken.toLowerCase() !== args.paymentToken.toLowerCase()) return false;
|
|
5985
|
+
if (args.seller && row.seller.toLowerCase() !== args.seller.toLowerCase()) return false;
|
|
5986
|
+
return true;
|
|
5987
|
+
}
|
|
5988
|
+
function listFrom(items, source) {
|
|
5989
|
+
return { items, nextCursor: null, source };
|
|
5990
|
+
}
|
|
5991
|
+
async function fetchContinuumDaoMarketplaceConfig(args = {}) {
|
|
5992
|
+
const url = `${apiBase(args)}/marketplace/config`;
|
|
5993
|
+
const res = await getJson(url);
|
|
5994
|
+
if (res.ok && res.body && typeof res.body === "object") {
|
|
5995
|
+
return { ...res.body, source: "api" };
|
|
5996
|
+
}
|
|
5997
|
+
if (!res.ok && !isOffline(res.status)) throw res.error;
|
|
5998
|
+
return readMarketplaceConfigFromChain({
|
|
5999
|
+
chainId: args.chainId ?? exports.CONTINUUM_DAO_LINEA_CHAIN_ID,
|
|
6000
|
+
rpcUrl: args.rpcUrl ?? ""
|
|
6001
|
+
});
|
|
6002
|
+
}
|
|
6003
|
+
async function fetchContinuumDaoMarketplaceListings(args = {}) {
|
|
6004
|
+
const includeInactive = Boolean(args.includeInactive);
|
|
6005
|
+
const url = `${apiBase(args)}/marketplace/listings${qs({
|
|
6006
|
+
includeInactive,
|
|
6007
|
+
paymentToken: args.paymentToken,
|
|
6008
|
+
tokenId: args.tokenId,
|
|
6009
|
+
creator: args.creator,
|
|
6010
|
+
limit: args.limit ?? 100,
|
|
6011
|
+
cursor: args.cursor,
|
|
6012
|
+
viewer: args.viewer
|
|
6013
|
+
})}`;
|
|
6014
|
+
const res = await getJson(url);
|
|
6015
|
+
if (res.ok) {
|
|
6016
|
+
const body = res.body;
|
|
6017
|
+
return { items: body.items ?? [], nextCursor: body.nextCursor ?? null, source: "api" };
|
|
6018
|
+
}
|
|
6019
|
+
if (args.cursor || !isOffline(res.status)) throw res.error;
|
|
6020
|
+
const book = await logsBook(args);
|
|
6021
|
+
return listFrom(book.listings.filter((row) => matchOrder(row, args, includeInactive)), "logs");
|
|
6022
|
+
}
|
|
6023
|
+
async function fetchContinuumDaoMarketplaceOfferings(args = {}) {
|
|
6024
|
+
const includeInactive = Boolean(args.includeInactive);
|
|
6025
|
+
const url = `${apiBase(args)}/marketplace/offerings${qs({
|
|
6026
|
+
includeInactive,
|
|
6027
|
+
paymentToken: args.paymentToken,
|
|
6028
|
+
tokenId: args.tokenId,
|
|
6029
|
+
creator: args.creator,
|
|
6030
|
+
limit: args.limit ?? 100,
|
|
6031
|
+
cursor: args.cursor,
|
|
6032
|
+
viewer: args.viewer
|
|
6033
|
+
})}`;
|
|
6034
|
+
const res = await getJson(url);
|
|
6035
|
+
if (res.ok) {
|
|
6036
|
+
const body = res.body;
|
|
6037
|
+
return { items: body.items ?? [], nextCursor: body.nextCursor ?? null, source: "api" };
|
|
6038
|
+
}
|
|
6039
|
+
if (args.cursor || !isOffline(res.status)) throw res.error;
|
|
6040
|
+
const book = await logsBook(args);
|
|
6041
|
+
return listFrom(book.offerings.filter((row) => matchOrder(row, args, includeInactive)), "logs");
|
|
6042
|
+
}
|
|
6043
|
+
async function fetchContinuumDaoMarketplaceAuctions(args = {}) {
|
|
6044
|
+
const includeInactive = Boolean(args.includeInactive);
|
|
6045
|
+
const url = `${apiBase(args)}/marketplace/auctions${qs({
|
|
6046
|
+
includeInactive,
|
|
6047
|
+
paymentToken: args.paymentToken,
|
|
6048
|
+
tokenId: args.tokenId,
|
|
6049
|
+
seller: args.seller,
|
|
6050
|
+
limit: args.limit ?? 100,
|
|
6051
|
+
cursor: args.cursor,
|
|
6052
|
+
viewer: args.viewer
|
|
6053
|
+
})}`;
|
|
6054
|
+
const res = await getJson(url);
|
|
6055
|
+
if (res.ok) {
|
|
6056
|
+
const body = res.body;
|
|
6057
|
+
return {
|
|
6058
|
+
items: (body.items ?? []).map((row) => ({ ...row, bids: row.bids ?? [] })),
|
|
6059
|
+
nextCursor: body.nextCursor ?? null,
|
|
6060
|
+
source: "api"
|
|
6061
|
+
};
|
|
6062
|
+
}
|
|
6063
|
+
if (args.cursor || !isOffline(res.status)) throw res.error;
|
|
6064
|
+
const book = await logsBook(args);
|
|
6065
|
+
return listFrom(book.auctions.filter((row) => matchAuction(row, args, includeInactive)), "logs");
|
|
6066
|
+
}
|
|
6067
|
+
async function fetchContinuumDaoMarketplaceToken(args) {
|
|
6068
|
+
const url = `${apiBase(args)}/marketplace/tokens/${encodeURIComponent(args.tokenId)}${qs({ viewer: args.viewer })}`;
|
|
6069
|
+
const res = await getJson(url);
|
|
6070
|
+
if (res.ok && res.body && typeof res.body === "object") {
|
|
6071
|
+
return { ...res.body, source: "api" };
|
|
6072
|
+
}
|
|
6073
|
+
if (!res.ok && !isOffline(res.status)) throw res.error;
|
|
6074
|
+
const book = await logsBook(args);
|
|
6075
|
+
const listings = book.listings.filter((row) => row.tokenId === args.tokenId);
|
|
6076
|
+
const offerings = book.offerings.filter((row) => row.tokenId === args.tokenId);
|
|
6077
|
+
const auctions = book.auctions.filter((row) => row.tokenId === args.tokenId);
|
|
6078
|
+
return {
|
|
6079
|
+
token: { tokenId: args.tokenId },
|
|
6080
|
+
listing: listings.find((row) => isOpenOrder(row)) ?? null,
|
|
6081
|
+
offerings: offerings.filter((row) => isOpenOrder(row)),
|
|
6082
|
+
auction: auctions.find((row) => isLiveAuctionStatus(row.derivedStatus)) ?? null,
|
|
6083
|
+
history: {
|
|
6084
|
+
listings: listings.filter((row) => !isOpenOrder(row)),
|
|
6085
|
+
offerings: offerings.filter((row) => !isOpenOrder(row)),
|
|
6086
|
+
auctions: auctions.filter((row) => !isLiveAuctionStatus(row.derivedStatus))
|
|
6087
|
+
},
|
|
6088
|
+
source: "logs"
|
|
6089
|
+
};
|
|
6090
|
+
}
|
|
6091
|
+
async function fetchContinuumDaoMarketplaceFeePreview(args) {
|
|
6092
|
+
const url = `${apiBase(args)}/marketplace/fee-preview${qs({ tokenId: args.tokenId, price: args.price })}`;
|
|
6093
|
+
const res = await getJson(url);
|
|
6094
|
+
if (res.ok && res.body && typeof res.body === "object") {
|
|
6095
|
+
return { ...res.body, source: "api" };
|
|
6096
|
+
}
|
|
6097
|
+
if (!res.ok && !isOffline(res.status)) throw res.error;
|
|
6098
|
+
return readMarketplaceFeePreviewFromChain({
|
|
6099
|
+
chainId: args.chainId ?? exports.CONTINUUM_DAO_LINEA_CHAIN_ID,
|
|
6100
|
+
rpcUrl: args.rpcUrl ?? "",
|
|
6101
|
+
tokenId: BigInt(args.tokenId),
|
|
6102
|
+
price: BigInt(args.price)
|
|
6103
|
+
});
|
|
6104
|
+
}
|
|
6105
|
+
async function fetchContinuumDaoMarketplaceActivity(args) {
|
|
6106
|
+
const url = `${apiBase(args)}/marketplace/users/${encodeURIComponent(args.address)}/activity${qs({ limit: args.limit ?? 50 })}`;
|
|
6107
|
+
const res = await getJson(url);
|
|
6108
|
+
if (res.ok && res.body && typeof res.body === "object") {
|
|
6109
|
+
const body = res.body;
|
|
6110
|
+
return {
|
|
6111
|
+
address: args.address,
|
|
6112
|
+
orders: body.orders ?? [],
|
|
6113
|
+
auctions: (body.auctions ?? []).map((row) => ({ ...row, bids: row.bids ?? [] })),
|
|
6114
|
+
source: "api"
|
|
6115
|
+
};
|
|
6116
|
+
}
|
|
6117
|
+
if (!res.ok && !isOffline(res.status)) throw res.error;
|
|
6118
|
+
const book = await logsBook(args);
|
|
6119
|
+
const address = args.address.toLowerCase();
|
|
6120
|
+
const orders = [...book.listings, ...book.offerings].filter((row) => {
|
|
6121
|
+
return row.creator.toLowerCase() === address || (row.counterparty ?? "").toLowerCase() === address || (row.seller ?? "").toLowerCase() === address || (row.buyer ?? "").toLowerCase() === address;
|
|
6122
|
+
});
|
|
6123
|
+
const auctions = book.auctions.filter((row) => {
|
|
6124
|
+
return row.seller.toLowerCase() === address || (row.buyer ?? "").toLowerCase() === address || (row.highestBidder ?? "").toLowerCase() === address || row.bids.some((bid) => bid.bidder.toLowerCase() === address);
|
|
6125
|
+
});
|
|
6126
|
+
return { address: args.address, orders, auctions, source: "logs" };
|
|
6127
|
+
}
|
|
6128
|
+
|
|
6129
|
+
// src/protocols/evm/continuum-dao/marketplaceSearch.ts
|
|
6130
|
+
init_constants();
|
|
6131
|
+
var LOCKED_ABI = [viem.parseAbiItem("function locked(uint256 tokenId) view returns (int128 amount, uint256 end)")];
|
|
6132
|
+
var MONTH_SECONDS = 30 * 24 * 60 * 60;
|
|
6133
|
+
var PAGE_SIZE = 100;
|
|
6134
|
+
var MAX_PAGES = 20;
|
|
6135
|
+
var DEFAULT_LIMIT = 10;
|
|
6136
|
+
var MAX_LIMIT = 25;
|
|
6137
|
+
var DEFAULT_DIRECTION = {
|
|
6138
|
+
pricePerLockedCtm: "asc",
|
|
6139
|
+
price: "asc",
|
|
6140
|
+
locked: "desc",
|
|
6141
|
+
unlock: "asc",
|
|
6142
|
+
deadline: "asc"
|
|
6143
|
+
};
|
|
6144
|
+
function same3(a, b) {
|
|
6145
|
+
if (!a || !b) return false;
|
|
6146
|
+
try {
|
|
6147
|
+
return viem.getAddress(a) === viem.getAddress(b);
|
|
6148
|
+
} catch {
|
|
6149
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
6150
|
+
}
|
|
6151
|
+
}
|
|
6152
|
+
function attachedKey(keygen, protocolStatus) {
|
|
6153
|
+
if (protocolStatus === "KeyGenAttached") return true;
|
|
6154
|
+
const value = (keygen ?? "").trim().toLowerCase();
|
|
6155
|
+
return Boolean(value && value !== "0" && !/^0x0+$/.test(value));
|
|
6156
|
+
}
|
|
6157
|
+
function asBig(value) {
|
|
6158
|
+
try {
|
|
6159
|
+
return BigInt(value || "0");
|
|
6160
|
+
} catch {
|
|
6161
|
+
return 0n;
|
|
6162
|
+
}
|
|
6163
|
+
}
|
|
6164
|
+
function parseCtm(raw) {
|
|
6165
|
+
const trimmed = raw?.trim();
|
|
6166
|
+
if (!trimmed) return null;
|
|
6167
|
+
return viem.parseUnits(trimmed, 18);
|
|
6168
|
+
}
|
|
6169
|
+
function parseTime(raw) {
|
|
6170
|
+
const trimmed = raw?.trim();
|
|
6171
|
+
if (!trimmed) return null;
|
|
6172
|
+
if (/^\d+$/.test(trimmed)) {
|
|
6173
|
+
const n = Number(trimmed);
|
|
6174
|
+
if (!Number.isFinite(n)) throw new Error("Unlock bound must be an ISO date or unix seconds.");
|
|
6175
|
+
return n > 1e12 ? Math.floor(n / 1e3) : n;
|
|
6176
|
+
}
|
|
6177
|
+
const ms = Date.parse(trimmed);
|
|
6178
|
+
if (Number.isNaN(ms)) throw new Error("Unlock bound must be an ISO date or unix seconds.");
|
|
6179
|
+
return Math.floor(ms / 1e3);
|
|
6180
|
+
}
|
|
6181
|
+
function paymentMeta(address) {
|
|
6182
|
+
const lower = address.toLowerCase();
|
|
6183
|
+
if (lower === exports.MARKETPLACE_USDC_LINEA_ADDRESS.toLowerCase()) return { symbol: "USDC", decimals: 6 };
|
|
6184
|
+
if (lower === exports.MARKETPLACE_WETH_LINEA_ADDRESS.toLowerCase()) return { symbol: "WETH", decimals: 18 };
|
|
6185
|
+
if (lower === exports.CTM_TOKEN_ADDRESS.toLowerCase()) return { symbol: "CTM", decimals: 18 };
|
|
6186
|
+
return { symbol: "token", decimals: 18 };
|
|
6187
|
+
}
|
|
6188
|
+
function trimDecimal(value) {
|
|
6189
|
+
return value.replace(/(\.\d*?[1-9])0+$/, "$1").replace(/\.0+$/, "");
|
|
6190
|
+
}
|
|
6191
|
+
function humanAmount(wei, decimals) {
|
|
6192
|
+
return trimDecimal(viem.formatUnits(wei, decimals));
|
|
6193
|
+
}
|
|
6194
|
+
function positive(value) {
|
|
6195
|
+
const trimmed = (value ?? "").trim();
|
|
6196
|
+
return trimmed && trimmed !== "0" ? trimmed : "";
|
|
6197
|
+
}
|
|
6198
|
+
function unlockUnixFrom(row) {
|
|
6199
|
+
const iso2 = positive(row.unlockTimeAt);
|
|
6200
|
+
if (iso2) {
|
|
6201
|
+
const ms = Date.parse(iso2);
|
|
6202
|
+
if (!Number.isNaN(ms)) return Math.floor(ms / 1e3);
|
|
6203
|
+
}
|
|
6204
|
+
const unix = positive(row.unlockTime) || positive(row.snapshotEnd);
|
|
6205
|
+
return unix ? Number(unix) : 0;
|
|
6206
|
+
}
|
|
6207
|
+
function lockedFrom(row) {
|
|
6208
|
+
return asBig(positive(row.lockedCTM) || positive(row.currentLockedAmount) || positive(row.snapshotAmount));
|
|
6209
|
+
}
|
|
6210
|
+
function listingCandidate(row) {
|
|
6211
|
+
const attached = attachedKey(row.keygen, row.protocolStatus);
|
|
6212
|
+
const open = row.protocolStatus === "Open" || row.storedStatus === "Open";
|
|
6213
|
+
return {
|
|
6214
|
+
kind: "listing",
|
|
6215
|
+
tokenId: row.tokenId,
|
|
6216
|
+
onchainIndex: row.onchainIndex,
|
|
6217
|
+
seller: row.seller ?? row.creator,
|
|
6218
|
+
paymentToken: row.paymentToken,
|
|
6219
|
+
price: asBig(row.price),
|
|
6220
|
+
priceBasis: "ask",
|
|
6221
|
+
locked: lockedFrom(row),
|
|
6222
|
+
unlockUnix: unlockUnixFrom(row),
|
|
6223
|
+
deadlineUnix: Number(row.deadlineUnix || "0") || 0,
|
|
6224
|
+
attached,
|
|
6225
|
+
fillable: open && !attached,
|
|
6226
|
+
protocolStatus: row.protocolStatus,
|
|
6227
|
+
storedStatus: row.storedStatus,
|
|
6228
|
+
keygen: row.keygen
|
|
6229
|
+
};
|
|
6230
|
+
}
|
|
6231
|
+
function auctionCandidate(row) {
|
|
6232
|
+
const attached = attachedKey(row.keygen, row.storedStatus);
|
|
6233
|
+
const bid = asBig(row.highestBid);
|
|
6234
|
+
const reserve = asBig(row.reservePrice);
|
|
6235
|
+
const live = row.derivedStatus === "Pending" || row.derivedStatus === "Active";
|
|
6236
|
+
return {
|
|
6237
|
+
kind: "auction",
|
|
6238
|
+
tokenId: row.tokenId,
|
|
6239
|
+
onchainIndex: row.onchainIndex,
|
|
6240
|
+
seller: row.seller,
|
|
6241
|
+
paymentToken: row.paymentToken,
|
|
6242
|
+
price: bid > 0n ? bid : reserve,
|
|
6243
|
+
priceBasis: bid > 0n ? "highestBid" : "reserve",
|
|
6244
|
+
locked: lockedFrom(row),
|
|
6245
|
+
unlockUnix: unlockUnixFrom(row),
|
|
6246
|
+
deadlineUnix: Number(row.deadlineUnix || "0") || 0,
|
|
6247
|
+
attached,
|
|
6248
|
+
fillable: live && !attached,
|
|
6249
|
+
protocolStatus: row.derivedStatus,
|
|
6250
|
+
storedStatus: row.storedStatus,
|
|
6251
|
+
keygen: row.keygen
|
|
6252
|
+
};
|
|
6253
|
+
}
|
|
6254
|
+
function applyLock(row, lock) {
|
|
6255
|
+
if (row.locked > 0n && row.unlockUnix > 0) return row;
|
|
6256
|
+
if (!lock) return row;
|
|
6257
|
+
return {
|
|
6258
|
+
...row,
|
|
6259
|
+
locked: row.locked > 0n ? row.locked : lock.amount,
|
|
6260
|
+
unlockUnix: row.unlockUnix > 0 ? row.unlockUnix : lock.end
|
|
6261
|
+
};
|
|
6262
|
+
}
|
|
6263
|
+
function rankMarketplaceSearchHits(rows, query, nowUnix = Math.floor(Date.now() / 1e3)) {
|
|
6264
|
+
const sort = query.sort ?? "pricePerLockedCtm";
|
|
6265
|
+
const direction = query.sortDirection ?? DEFAULT_DIRECTION[sort];
|
|
6266
|
+
const minLocked = parseCtm(query.minLockedCtm);
|
|
6267
|
+
const maxLocked = parseCtm(query.maxLockedCtm);
|
|
6268
|
+
const unlockAfter = parseTime(query.unlockAfter);
|
|
6269
|
+
const unlockBefore = parseTime(query.unlockBefore);
|
|
6270
|
+
const monthCap = query.maxUnlockMonths != null && Number.isFinite(query.maxUnlockMonths) ? nowUnix + Math.floor(query.maxUnlockMonths * MONTH_SECONDS) : null;
|
|
6271
|
+
const executor = query.executor?.trim();
|
|
6272
|
+
const excludeOwned = query.excludeOwned !== false && Boolean(executor);
|
|
6273
|
+
let matched = rows.filter((row) => {
|
|
6274
|
+
if (query.paymentToken && !same3(row.paymentToken, query.paymentToken)) return false;
|
|
6275
|
+
if (excludeOwned && same3(row.seller, executor)) return false;
|
|
6276
|
+
if (minLocked != null && row.locked < minLocked) return false;
|
|
6277
|
+
if (maxLocked != null && row.locked > maxLocked) return false;
|
|
6278
|
+
if (unlockAfter != null && row.unlockUnix < unlockAfter) return false;
|
|
6279
|
+
if (unlockBefore != null && (row.unlockUnix <= 0 || row.unlockUnix > unlockBefore)) return false;
|
|
6280
|
+
if (monthCap != null && (row.unlockUnix <= nowUnix || row.unlockUnix > monthCap)) return false;
|
|
6281
|
+
return true;
|
|
6282
|
+
});
|
|
6283
|
+
const priceSort = sort === "price" || sort === "pricePerLockedCtm";
|
|
6284
|
+
if (priceSort && !query.paymentToken) {
|
|
6285
|
+
const tokens = new Set(matched.map((row) => row.paymentToken.toLowerCase()));
|
|
6286
|
+
if (tokens.size > 1) {
|
|
6287
|
+
const symbols = [...tokens].map((token) => paymentMeta(token).symbol).join(", ");
|
|
6288
|
+
throw new Error(`Pass paymentToken to rank by price. These rows use ${symbols}.`);
|
|
6289
|
+
}
|
|
6290
|
+
}
|
|
6291
|
+
const asc = direction === "asc";
|
|
6292
|
+
const key = (row) => {
|
|
6293
|
+
if (sort === "locked") return row.locked;
|
|
6294
|
+
if (sort === "unlock") return BigInt(row.unlockUnix || 0);
|
|
6295
|
+
if (sort === "deadline") return BigInt(row.deadlineUnix || 0);
|
|
6296
|
+
if (sort === "pricePerLockedCtm") return row.locked > 0n ? row.price * 10n ** 18n / row.locked : 2n ** 255n - 1n;
|
|
6297
|
+
return row.price;
|
|
6298
|
+
};
|
|
6299
|
+
matched = [...matched].sort((a, b) => {
|
|
6300
|
+
if (a.fillable !== b.fillable) return a.fillable ? -1 : 1;
|
|
6301
|
+
if (sort === "pricePerLockedCtm" && a.locked <= 0n !== b.locked <= 0n) return a.locked <= 0n ? 1 : -1;
|
|
6302
|
+
const cmp = key(a) === key(b) ? 0 : key(a) < key(b) ? -1 : 1;
|
|
6303
|
+
if (cmp !== 0) return asc ? cmp : -cmp;
|
|
6304
|
+
return a.tokenId.localeCompare(b.tokenId);
|
|
6305
|
+
});
|
|
6306
|
+
const limit = Math.min(MAX_LIMIT, Math.max(1, query.limit ?? DEFAULT_LIMIT));
|
|
6307
|
+
return matched.slice(0, limit).map((row) => toHit(row, nowUnix));
|
|
6308
|
+
}
|
|
6309
|
+
function toHit(row, nowUnix) {
|
|
6310
|
+
const meta4 = paymentMeta(row.paymentToken);
|
|
6311
|
+
const perCtm = row.locked > 0n ? row.price * 10n ** 18n / row.locked : 0n;
|
|
6312
|
+
const months = row.unlockUnix > nowUnix ? ((row.unlockUnix - nowUnix) / MONTH_SECONDS).toFixed(1) : row.unlockUnix > 0 ? "0" : "";
|
|
6313
|
+
return {
|
|
6314
|
+
kind: row.kind,
|
|
6315
|
+
tokenId: row.tokenId,
|
|
6316
|
+
onchainIndex: row.onchainIndex,
|
|
6317
|
+
seller: row.seller,
|
|
6318
|
+
paymentToken: row.paymentToken,
|
|
6319
|
+
paymentSymbol: meta4.symbol,
|
|
6320
|
+
price: row.price.toString(),
|
|
6321
|
+
priceHuman: humanAmount(row.price, meta4.decimals),
|
|
6322
|
+
priceBasis: row.priceBasis,
|
|
6323
|
+
lockedCtm: row.locked.toString(),
|
|
6324
|
+
lockedCtmHuman: humanAmount(row.locked, 18),
|
|
6325
|
+
unlockAt: row.unlockUnix > 0 ? new Date(row.unlockUnix * 1e3).toISOString() : "",
|
|
6326
|
+
monthsToUnlock: months,
|
|
6327
|
+
pricePerLockedCtm: row.locked > 0n ? humanAmount(perCtm, meta4.decimals) : "",
|
|
6328
|
+
deadlineAt: row.deadlineUnix > 0 ? new Date(row.deadlineUnix * 1e3).toISOString() : "",
|
|
6329
|
+
attached: row.attached,
|
|
6330
|
+
fillable: row.fillable
|
|
6331
|
+
};
|
|
6332
|
+
}
|
|
6333
|
+
async function fillMissingLocks(rows, rpcUrl, chainId) {
|
|
6334
|
+
const missing = [...new Set(rows.filter((row) => row.locked <= 0n || row.unlockUnix <= 0).map((row) => row.tokenId))];
|
|
6335
|
+
if (missing.length === 0 || !rpcUrl?.trim()) return rows;
|
|
6336
|
+
const client = marketplacePublicClient(chainId, rpcUrl.trim());
|
|
6337
|
+
const locks = /* @__PURE__ */ new Map();
|
|
6338
|
+
for (let i = 0; i < missing.length; i += 40) {
|
|
6339
|
+
const chunk = missing.slice(i, i + 40);
|
|
6340
|
+
const results = await client.multicall({
|
|
6341
|
+
contracts: chunk.map((id) => ({
|
|
6342
|
+
address: exports.VOTING_ESCROW_LINEA_ADDRESS,
|
|
6343
|
+
abi: LOCKED_ABI,
|
|
6344
|
+
functionName: "locked",
|
|
6345
|
+
args: [BigInt(id)]
|
|
6346
|
+
})),
|
|
6347
|
+
allowFailure: true
|
|
6348
|
+
});
|
|
6349
|
+
results.forEach((result, index) => {
|
|
6350
|
+
if (result.status !== "success" || !result.result) return;
|
|
6351
|
+
const [amount, end] = result.result;
|
|
6352
|
+
const id = chunk[index];
|
|
6353
|
+
if (!id) return;
|
|
6354
|
+
locks.set(id, { amount: amount < 0n ? 0n : amount, end: Number(end) });
|
|
6355
|
+
});
|
|
6356
|
+
}
|
|
6357
|
+
return rows.map((row) => applyLock(row, locks.get(row.tokenId)));
|
|
6358
|
+
}
|
|
6359
|
+
async function collectKind(kind, args) {
|
|
6360
|
+
const rows = [];
|
|
6361
|
+
let cursor;
|
|
6362
|
+
let scanned = 0;
|
|
6363
|
+
let source = "api";
|
|
6364
|
+
let truncated = false;
|
|
6365
|
+
for (let page = 0; page < MAX_PAGES; page += 1) {
|
|
6366
|
+
const query = { ...args, includeInactive: false, limit: PAGE_SIZE, cursor };
|
|
6367
|
+
const res = kind === "listing" ? await fetchContinuumDaoMarketplaceListings(query) : await fetchContinuumDaoMarketplaceAuctions(query);
|
|
6368
|
+
source = res.source;
|
|
6369
|
+
scanned += res.items.length;
|
|
6370
|
+
for (const item of res.items) {
|
|
6371
|
+
rows.push(kind === "listing" ? listingCandidate(item) : auctionCandidate(item));
|
|
6372
|
+
}
|
|
6373
|
+
if (res.source === "logs" || !res.nextCursor) return { rows, scanned, truncated, source };
|
|
6374
|
+
cursor = res.nextCursor;
|
|
6375
|
+
}
|
|
6376
|
+
truncated = true;
|
|
6377
|
+
return { rows, scanned, truncated, source };
|
|
6378
|
+
}
|
|
6379
|
+
async function searchContinuumDaoMarketplace(args = {}) {
|
|
6380
|
+
const kind = args.kind ?? "listing";
|
|
6381
|
+
const chainId = args.chainId ?? exports.CONTINUUM_DAO_LINEA_CHAIN_ID;
|
|
6382
|
+
const parts = await Promise.all([
|
|
6383
|
+
kind !== "auction" ? collectKind("listing", args) : Promise.resolve(null),
|
|
6384
|
+
kind !== "listing" ? collectKind("auction", args) : Promise.resolve(null)
|
|
6385
|
+
]);
|
|
6386
|
+
const collected = parts.flatMap((part) => part?.rows ?? []);
|
|
6387
|
+
const withLocks = await fillMissingLocks(collected, args.rpcUrl, chainId);
|
|
6388
|
+
const sort = args.sort ?? "pricePerLockedCtm";
|
|
6389
|
+
const items = rankMarketplaceSearchHits(withLocks, args);
|
|
6390
|
+
return {
|
|
6391
|
+
sort,
|
|
6392
|
+
sortDirection: args.sortDirection ?? DEFAULT_DIRECTION[sort],
|
|
6393
|
+
paymentToken: args.paymentToken ?? null,
|
|
6394
|
+
scanned: parts.reduce((sum, part) => sum + (part?.scanned ?? 0), 0),
|
|
6395
|
+
truncated: parts.some((part) => part?.truncated),
|
|
6396
|
+
items,
|
|
6397
|
+
source: parts.some((part) => part?.source === "logs") ? "logs" : "api"
|
|
6398
|
+
};
|
|
6399
|
+
}
|
|
6400
|
+
|
|
6401
|
+
// src/protocols/evm/continuum-dao/marketplaceFeeAlternative.ts
|
|
6402
|
+
init_constants();
|
|
6403
|
+
var PAGE_SIZE2 = 100;
|
|
6404
|
+
var MAX_PAGES2 = 20;
|
|
6405
|
+
var feeAbi = viem.parseAbi([
|
|
6406
|
+
"function veCtmThresholdPower() view returns (uint256)",
|
|
6407
|
+
"function getActiveRates() view returns (uint256 monthlyFee, uint256 freeSignaturesPerMonth, uint256 overageFeePerSignature)",
|
|
6408
|
+
"function FEE_TOKEN() view returns (address)",
|
|
6409
|
+
"function ctmPerFeeToken() view returns (uint256)",
|
|
6410
|
+
"function locked(uint256 tokenId) view returns (int128 amount, uint256 end)",
|
|
6411
|
+
"function balanceOfNFT(uint256 tokenId) view returns (uint256)"
|
|
6412
|
+
]);
|
|
6413
|
+
function trimDecimal2(value) {
|
|
6414
|
+
return value.replace(/(\.\d*?[1-9])0+$/, "$1").replace(/\.0+$/, "");
|
|
6415
|
+
}
|
|
6416
|
+
function human(wei, decimals) {
|
|
6417
|
+
return trimDecimal2(viem.formatUnits(wei, decimals));
|
|
6418
|
+
}
|
|
6419
|
+
function paymentMeta2(address) {
|
|
6420
|
+
const lower = address.toLowerCase();
|
|
6421
|
+
if (lower === exports.MARKETPLACE_USDC_LINEA_ADDRESS.toLowerCase()) return { symbol: "USDC", decimals: 6 };
|
|
6422
|
+
if (lower === exports.MARKETPLACE_WETH_LINEA_ADDRESS.toLowerCase()) return { symbol: "WETH", decimals: 18 };
|
|
6423
|
+
if (lower === exports.CTM_TOKEN_ADDRESS.toLowerCase()) return { symbol: "CTM", decimals: 18 };
|
|
6424
|
+
return { symbol: "token", decimals: 18 };
|
|
6425
|
+
}
|
|
6426
|
+
function monthsOfFees(price, monthly) {
|
|
6427
|
+
if (monthly <= 0n || price < 0n) return null;
|
|
6428
|
+
const tenths = price * 10n / monthly;
|
|
6429
|
+
const whole = tenths / 10n;
|
|
6430
|
+
const frac = tenths % 10n;
|
|
6431
|
+
return frac === 0n ? whole.toString() : `${whole}.${frac}`;
|
|
6432
|
+
}
|
|
6433
|
+
function votingPowerAboveUntil(args) {
|
|
6434
|
+
if (args.votingPower <= args.threshold) return null;
|
|
6435
|
+
if (args.unlockUnix <= args.nowUnix) return null;
|
|
6436
|
+
if (args.threshold <= 0n) return args.unlockUnix;
|
|
6437
|
+
const remaining = BigInt(args.unlockUnix - args.nowUnix);
|
|
6438
|
+
const drop = remaining * args.threshold / args.votingPower;
|
|
6439
|
+
return args.unlockUnix - Number(drop);
|
|
6440
|
+
}
|
|
6441
|
+
function pickFeeAlternativeExample(rows, preferredToken) {
|
|
6442
|
+
const fillable = rows.filter((row) => row.fillable && row.locked > 0n && row.votingPower > 0n);
|
|
6443
|
+
const preferred = preferredToken ? fillable.filter((row) => row.paymentToken.toLowerCase() === preferredToken.toLowerCase()) : [];
|
|
6444
|
+
const pool = preferred.length > 0 ? preferred : fillable;
|
|
6445
|
+
const perCtm = (row) => row.price * 10n ** 18n / row.locked;
|
|
6446
|
+
return [...pool].sort((a, b) => {
|
|
6447
|
+
const left = perCtm(a);
|
|
6448
|
+
const right = perCtm(b);
|
|
6449
|
+
if (left === right) return a.tokenId.localeCompare(b.tokenId);
|
|
6450
|
+
return left < right ? -1 : 1;
|
|
6451
|
+
})[0] ?? null;
|
|
6452
|
+
}
|
|
6453
|
+
function iso(unix) {
|
|
6454
|
+
return unix > 0 ? new Date(unix * 1e3).toISOString() : "";
|
|
6455
|
+
}
|
|
6456
|
+
function buildFeeAlternativeSummary(args) {
|
|
6457
|
+
const fee = `${args.monthlyFeeHuman} ${args.monthlyFeeSymbol}`;
|
|
6458
|
+
const year = `${args.annualFeeHuman} ${args.monthlyFeeSymbol} (${args.annualFeeCtmHuman} CTM)`;
|
|
6459
|
+
const lead = `Paying this month is ${fee}. A year for one KeyGen is ${year}. As an alternative, buy a veCTM and attach it. Locked CTM and voting power both have to be above ${args.thresholdHuman}. One attached veCTM waives the monthly fee for KeyGens in that group, and VPN follows a qualifying group on the node. Voting power decays, so a lock sitting on the line can miss a later month.`;
|
|
6460
|
+
if (!args.example) {
|
|
6461
|
+
return `${lead} No live direct listing is above that threshold right now.`;
|
|
6462
|
+
}
|
|
6463
|
+
const row = args.example;
|
|
6464
|
+
const compare = row.monthsOfFees ? ` That ask is about ${row.monthsOfFees} months of fees. The ask buys a lock you still hold; the monthly fee is spent.` : ` The listing is priced in ${row.paymentSymbol}, which is a different token from the fee.`;
|
|
6465
|
+
return `${lead} Example direct listing #${row.tokenId}: ${row.priceHuman} ${row.paymentSymbol} for ${row.lockedCtmHuman} CTM, unlocks ${row.unlockAt}. Voting power stays above the threshold until ${row.staysAboveThresholdUntil}.${compare}`;
|
|
6466
|
+
}
|
|
6467
|
+
async function readFeeSide(rpcUrl, chainId) {
|
|
6468
|
+
const client = marketplacePublicClient(chainId, rpcUrl);
|
|
6469
|
+
const wallet = exports.MULTISIGN_AGENT_WALLET_LINEA_ADDRESS;
|
|
6470
|
+
const [threshold, rates, feeToken, ctmPerFeeToken] = await Promise.all([
|
|
6471
|
+
client.readContract({ address: wallet, abi: feeAbi, functionName: "veCtmThresholdPower" }),
|
|
6472
|
+
client.readContract({ address: wallet, abi: feeAbi, functionName: "getActiveRates" }),
|
|
6473
|
+
client.readContract({ address: wallet, abi: feeAbi, functionName: "FEE_TOKEN" }),
|
|
6474
|
+
client.readContract({ address: wallet, abi: feeAbi, functionName: "ctmPerFeeToken" })
|
|
6475
|
+
]);
|
|
6476
|
+
const monthlyFee = rates[0];
|
|
6477
|
+
const monthlyFeeCtm = ctmPerFeeToken > 0n ? monthlyFee * ctmPerFeeToken / exports.CTM_FEE_RATE_SCALE : 0n;
|
|
6478
|
+
return { threshold, monthlyFee, monthlyFeeCtm, feeToken: viem.getAddress(feeToken) };
|
|
6479
|
+
}
|
|
6480
|
+
async function collectListings(args) {
|
|
6481
|
+
const rows = [];
|
|
6482
|
+
let cursor;
|
|
6483
|
+
let scanned = 0;
|
|
6484
|
+
let source = "api";
|
|
6485
|
+
let truncated = false;
|
|
6486
|
+
for (let page = 0; page < MAX_PAGES2; page += 1) {
|
|
6487
|
+
const res = await fetchContinuumDaoMarketplaceListings({ ...args, includeInactive: false, limit: PAGE_SIZE2, cursor });
|
|
6488
|
+
source = res.source;
|
|
6489
|
+
scanned += res.items.length;
|
|
6490
|
+
rows.push(...res.items.map(listingCandidate));
|
|
6491
|
+
if (res.source === "logs" || !res.nextCursor) return { rows, scanned, truncated, source };
|
|
6492
|
+
cursor = res.nextCursor;
|
|
6493
|
+
}
|
|
6494
|
+
return { rows, scanned, truncated: true, source };
|
|
6495
|
+
}
|
|
6496
|
+
async function fillLocks(rows, rpcUrl, chainId) {
|
|
6497
|
+
const missing = [...new Set(rows.filter((row) => row.locked <= 0n || row.unlockUnix <= 0).map((row) => row.tokenId))];
|
|
6498
|
+
if (missing.length === 0) return rows;
|
|
6499
|
+
const client = marketplacePublicClient(chainId, rpcUrl);
|
|
6500
|
+
const locks = /* @__PURE__ */ new Map();
|
|
6501
|
+
for (let i = 0; i < missing.length; i += 40) {
|
|
6502
|
+
const chunk = missing.slice(i, i + 40);
|
|
6503
|
+
const results = await client.multicall({
|
|
6504
|
+
contracts: chunk.map((id) => ({
|
|
6505
|
+
address: exports.VOTING_ESCROW_LINEA_ADDRESS,
|
|
6506
|
+
abi: feeAbi,
|
|
6507
|
+
functionName: "locked",
|
|
6508
|
+
args: [BigInt(id)]
|
|
6509
|
+
})),
|
|
6510
|
+
allowFailure: true
|
|
6511
|
+
});
|
|
6512
|
+
results.forEach((result, index) => {
|
|
6513
|
+
if (result.status !== "success" || !result.result) return;
|
|
6514
|
+
const id = chunk[index];
|
|
6515
|
+
if (!id) return;
|
|
6516
|
+
const [amount, end] = result.result;
|
|
6517
|
+
locks.set(id, { amount: amount < 0n ? 0n : amount, end: Number(end) });
|
|
6518
|
+
});
|
|
6519
|
+
}
|
|
6520
|
+
return rows.map((row) => {
|
|
6521
|
+
const lock = locks.get(row.tokenId);
|
|
6522
|
+
if (!lock) return row;
|
|
6523
|
+
return { ...row, locked: row.locked > 0n ? row.locked : lock.amount, unlockUnix: row.unlockUnix > 0 ? row.unlockUnix : lock.end };
|
|
6524
|
+
});
|
|
6525
|
+
}
|
|
6526
|
+
async function readVotingPower(tokenIds, rpcUrl, chainId) {
|
|
6527
|
+
const client = marketplacePublicClient(chainId, rpcUrl);
|
|
6528
|
+
const power = /* @__PURE__ */ new Map();
|
|
6529
|
+
for (let i = 0; i < tokenIds.length; i += 40) {
|
|
6530
|
+
const chunk = tokenIds.slice(i, i + 40);
|
|
6531
|
+
const results = await client.multicall({
|
|
6532
|
+
contracts: chunk.map((id) => ({
|
|
6533
|
+
address: exports.VOTING_ESCROW_LINEA_ADDRESS,
|
|
6534
|
+
abi: feeAbi,
|
|
6535
|
+
functionName: "balanceOfNFT",
|
|
6536
|
+
args: [BigInt(id)]
|
|
6537
|
+
})),
|
|
6538
|
+
allowFailure: true
|
|
6539
|
+
});
|
|
6540
|
+
results.forEach((result, index) => {
|
|
6541
|
+
const id = chunk[index];
|
|
6542
|
+
if (!id || result.status !== "success") return;
|
|
6543
|
+
power.set(id, result.result);
|
|
6544
|
+
});
|
|
6545
|
+
}
|
|
6546
|
+
return power;
|
|
6547
|
+
}
|
|
6548
|
+
async function quoteContinuumDaoMarketplaceFeeAlternative(args) {
|
|
6549
|
+
const rpcUrl = args.rpcUrl?.trim();
|
|
6550
|
+
if (!rpcUrl) throw new Error("Linea RPC is required to read the monthly fee and veCTM threshold.");
|
|
6551
|
+
const chainId = args.chainId ?? exports.CONTINUUM_DAO_LINEA_CHAIN_ID;
|
|
6552
|
+
const payment = args.payment ?? "fee";
|
|
6553
|
+
const nowUnix = Math.floor(Date.now() / 1e3);
|
|
6554
|
+
const fee = await readFeeSide(rpcUrl, chainId);
|
|
6555
|
+
const collected = await collectListings(args);
|
|
6556
|
+
const withLocks = await fillLocks(collected.rows, rpcUrl, chainId);
|
|
6557
|
+
const executor = args.executor?.trim();
|
|
6558
|
+
const visible = executor ? withLocks.filter((row) => {
|
|
6559
|
+
try {
|
|
6560
|
+
return viem.getAddress(row.seller) !== viem.getAddress(executor);
|
|
6561
|
+
} catch {
|
|
6562
|
+
return row.seller.toLowerCase() !== executor.toLowerCase();
|
|
6563
|
+
}
|
|
6564
|
+
}) : withLocks;
|
|
6565
|
+
const aboveLock = visible.filter((row) => row.fillable && row.locked > fee.threshold);
|
|
6566
|
+
const power = await readVotingPower(aboveLock.map((row) => row.tokenId), rpcUrl, chainId);
|
|
6567
|
+
const qualified = aboveLock.flatMap((row) => {
|
|
6568
|
+
const votingPower = power.get(row.tokenId);
|
|
6569
|
+
if (votingPower == null || votingPower <= fee.threshold) return [];
|
|
6570
|
+
return [
|
|
6571
|
+
{
|
|
6572
|
+
tokenId: row.tokenId,
|
|
6573
|
+
paymentToken: row.paymentToken,
|
|
6574
|
+
price: row.price,
|
|
6575
|
+
locked: row.locked,
|
|
6576
|
+
unlockUnix: row.unlockUnix,
|
|
6577
|
+
votingPower,
|
|
6578
|
+
fillable: row.fillable
|
|
6579
|
+
}
|
|
6580
|
+
];
|
|
6581
|
+
});
|
|
6582
|
+
const preferred = payment === "ctm" ? exports.CTM_TOKEN_ADDRESS : fee.feeToken;
|
|
6583
|
+
const picked = pickFeeAlternativeExample(qualified, preferred);
|
|
6584
|
+
const feeMeta = paymentMeta2(fee.feeToken);
|
|
6585
|
+
const example = picked ? toExample(picked, fee, payment, preferred, nowUnix) : null;
|
|
6586
|
+
const quoteBase = {
|
|
6587
|
+
payment,
|
|
6588
|
+
threshold: fee.threshold.toString(),
|
|
6589
|
+
thresholdHuman: human(fee.threshold, 18),
|
|
6590
|
+
monthlyFee: fee.monthlyFee.toString(),
|
|
6591
|
+
monthlyFeeHuman: human(fee.monthlyFee, feeMeta.decimals),
|
|
6592
|
+
monthlyFeeSymbol: feeMeta.symbol,
|
|
6593
|
+
annualFee: (fee.monthlyFee * 12n).toString(),
|
|
6594
|
+
annualFeeHuman: human(fee.monthlyFee * 12n, feeMeta.decimals),
|
|
6595
|
+
monthlyFeeCtm: fee.monthlyFeeCtm.toString(),
|
|
6596
|
+
monthlyFeeCtmHuman: human(fee.monthlyFeeCtm, 18),
|
|
6597
|
+
annualFeeCtm: (fee.monthlyFeeCtm * 12n).toString(),
|
|
6598
|
+
annualFeeCtmHuman: human(fee.monthlyFeeCtm * 12n, 18),
|
|
6599
|
+
feeToken: fee.feeToken,
|
|
6600
|
+
example,
|
|
6601
|
+
scanned: collected.scanned,
|
|
6602
|
+
truncated: collected.truncated,
|
|
6603
|
+
source: collected.source
|
|
6604
|
+
};
|
|
6605
|
+
return {
|
|
6606
|
+
...quoteBase,
|
|
6607
|
+
summary: buildFeeAlternativeSummary({
|
|
6608
|
+
thresholdHuman: quoteBase.thresholdHuman,
|
|
6609
|
+
monthlyFeeHuman: quoteBase.monthlyFeeHuman,
|
|
6610
|
+
monthlyFeeSymbol: quoteBase.monthlyFeeSymbol,
|
|
6611
|
+
annualFeeHuman: quoteBase.annualFeeHuman,
|
|
6612
|
+
annualFeeCtmHuman: quoteBase.annualFeeCtmHuman,
|
|
6613
|
+
example
|
|
6614
|
+
})
|
|
6615
|
+
};
|
|
6616
|
+
}
|
|
6617
|
+
function toExample(row, fee, payment, preferred, nowUnix) {
|
|
6618
|
+
const meta4 = paymentMeta2(row.paymentToken);
|
|
6619
|
+
const same5 = row.paymentToken.toLowerCase() === preferred.toLowerCase();
|
|
6620
|
+
const monthly = payment === "ctm" ? fee.monthlyFeeCtm : fee.monthlyFee;
|
|
6621
|
+
const until = votingPowerAboveUntil({
|
|
6622
|
+
votingPower: row.votingPower,
|
|
6623
|
+
threshold: fee.threshold,
|
|
6624
|
+
nowUnix,
|
|
6625
|
+
unlockUnix: row.unlockUnix
|
|
6626
|
+
});
|
|
6627
|
+
const perCtm = row.price * 10n ** 18n / row.locked;
|
|
6628
|
+
return {
|
|
6629
|
+
tokenId: row.tokenId,
|
|
6630
|
+
price: row.price.toString(),
|
|
6631
|
+
priceHuman: human(row.price, meta4.decimals),
|
|
6632
|
+
paymentToken: row.paymentToken,
|
|
6633
|
+
paymentSymbol: meta4.symbol,
|
|
6634
|
+
lockedCtm: row.locked.toString(),
|
|
6635
|
+
lockedCtmHuman: human(row.locked, 18),
|
|
6636
|
+
unlockAt: iso(row.unlockUnix),
|
|
6637
|
+
votingPower: row.votingPower.toString(),
|
|
6638
|
+
votingPowerHuman: human(row.votingPower, 18),
|
|
6639
|
+
staysAboveThresholdUntil: iso(until ?? 0),
|
|
6640
|
+
pricePerLockedCtm: human(perCtm, meta4.decimals),
|
|
6641
|
+
monthsOfFees: same5 ? monthsOfFees(row.price, monthly) : null,
|
|
6642
|
+
comparedTo: same5 ? payment : null,
|
|
6643
|
+
fillable: row.fillable
|
|
6644
|
+
};
|
|
6645
|
+
}
|
|
6646
|
+
|
|
6647
|
+
// src/protocols/evm/continuum-dao/marketplaceMultisign.ts
|
|
6648
|
+
init_buildBatch();
|
|
6649
|
+
init_constants();
|
|
6650
|
+
function parseWei(raw, label) {
|
|
6651
|
+
const value = typeof raw === "bigint" ? raw : BigInt(String(raw).trim());
|
|
6652
|
+
if (value < 0n) throw new Error(`${label} must be zero or greater.`);
|
|
6653
|
+
return value;
|
|
6654
|
+
}
|
|
6655
|
+
function parseTokenId2(raw) {
|
|
6656
|
+
const id = typeof raw === "bigint" ? raw : BigInt(String(raw).trim());
|
|
6657
|
+
if (id <= 0n) throw new Error("veCTM token id must be greater than zero.");
|
|
6658
|
+
return id;
|
|
6659
|
+
}
|
|
6660
|
+
function requireLinea(chainId) {
|
|
6661
|
+
if (chainId !== exports.CONTINUUM_DAO_LINEA_CHAIN_ID) {
|
|
6662
|
+
throw new Error("veCTM marketplace actions are Linea mainnet only.");
|
|
6663
|
+
}
|
|
6664
|
+
}
|
|
6665
|
+
function meta3(step, chainId, gasLimit) {
|
|
6666
|
+
return {
|
|
6667
|
+
destinationAddress: step.to,
|
|
6668
|
+
signatureText: continuumDaoSignatureText({ name: step.name, ...step.extra }, chainId),
|
|
6669
|
+
evm: {
|
|
6670
|
+
type: step.evmType,
|
|
6671
|
+
version: 1,
|
|
6672
|
+
chainId: String(chainId),
|
|
6673
|
+
protocolId: exports.CONTINUUM_DAO_MARKETPLACE_PROTOCOL_ID
|
|
6674
|
+
},
|
|
6675
|
+
continuumDaoMarketplace: { ...step.extra, name: step.name, gas: { baseGasUnits: gasLimit.toString() } }
|
|
6676
|
+
};
|
|
6677
|
+
}
|
|
6678
|
+
async function finalize2(steps, args, purposeSuffix) {
|
|
6679
|
+
const evmSteps = steps.map((s) => ({
|
|
6680
|
+
to: s.to,
|
|
6681
|
+
data: s.data,
|
|
6682
|
+
value: s.value,
|
|
6683
|
+
fallbackGas: s.fallbackGas
|
|
6684
|
+
}));
|
|
6685
|
+
const firstDataNo0x = evmSteps[0].data.startsWith("0x") ? evmSteps[0].data.slice(2) : evmSteps[0].data;
|
|
6686
|
+
return buildEvmMultisignBatch({
|
|
6687
|
+
context: {
|
|
6688
|
+
chainCategory: "evm",
|
|
6689
|
+
keyGen: args.keyGen,
|
|
6690
|
+
purposeText: args.purposeText,
|
|
6691
|
+
chainId: args.chainId,
|
|
6692
|
+
rpcUrl: args.rpcUrl.trim(),
|
|
6693
|
+
executorAddress: args.executorAddress,
|
|
6694
|
+
chainDetail: args.chainDetail,
|
|
6695
|
+
useCustomGas: args.useCustomGas,
|
|
6696
|
+
customGasChainDetails: args.customGasChainDetails
|
|
6697
|
+
},
|
|
6698
|
+
steps: evmSteps,
|
|
6699
|
+
purposeSuffix,
|
|
6700
|
+
firstMsgRawNo0x: firstDataNo0x,
|
|
6701
|
+
destinationAddress: steps[0].to,
|
|
6702
|
+
buildBatchMeta: ({ index, gasLimit }) => meta3(steps[index], args.chainId, gasLimit)
|
|
6703
|
+
});
|
|
6704
|
+
}
|
|
6705
|
+
async function build(args, input, purposeSuffix, snapshotArgs) {
|
|
6706
|
+
requireLinea(args.chainId);
|
|
6707
|
+
const executor = viem.getAddress(args.executorAddress);
|
|
6708
|
+
const tokenId = "tokenId" in input ? input.tokenId : 0n;
|
|
6709
|
+
const snap = await loadMarketplacePlanSnapshot({
|
|
6710
|
+
chainId: args.chainId,
|
|
6711
|
+
rpcUrl: args.rpcUrl,
|
|
6712
|
+
executor,
|
|
6713
|
+
tokenId,
|
|
6714
|
+
...snapshotArgs
|
|
6715
|
+
});
|
|
6716
|
+
const steps = planMarketplaceSteps(input, snap);
|
|
6717
|
+
return finalize2(steps, args, purposeSuffix);
|
|
6718
|
+
}
|
|
6719
|
+
async function buildEvmMultisignBodyContinuumDaoMarketplaceCreateListing(args) {
|
|
6720
|
+
const tokenId = parseTokenId2(args.tokenId);
|
|
6721
|
+
const paymentToken = viem.getAddress(args.paymentToken);
|
|
6722
|
+
const askWei = parseWei(args.askWei, "Ask");
|
|
6723
|
+
const deadline = parseWei(args.deadline, "Deadline");
|
|
6724
|
+
return build(
|
|
6725
|
+
args,
|
|
6726
|
+
{ action: "createListing", tokenId, paymentToken, askWei, deadline },
|
|
6727
|
+
`ContinuumDAO marketplace: list veCTM #${tokenId.toString()}.`,
|
|
6728
|
+
{ paymentToken }
|
|
6729
|
+
);
|
|
6730
|
+
}
|
|
6731
|
+
async function buildEvmMultisignBodyContinuumDaoMarketplaceDelist(args) {
|
|
6732
|
+
const tokenId = parseTokenId2(args.tokenId);
|
|
6733
|
+
return build(args, { action: "delist", tokenId }, `ContinuumDAO marketplace: delist veCTM #${tokenId.toString()}.`, {});
|
|
6734
|
+
}
|
|
6735
|
+
async function buildEvmMultisignBodyContinuumDaoMarketplaceFulfillListing(args) {
|
|
6736
|
+
const tokenId = parseTokenId2(args.tokenId);
|
|
6737
|
+
const seller = viem.getAddress(args.seller);
|
|
6738
|
+
const paymentToken = viem.getAddress(args.paymentToken);
|
|
6739
|
+
const priceWei = parseWei(args.priceWei, "Price");
|
|
6740
|
+
return build(
|
|
6741
|
+
args,
|
|
6742
|
+
{ action: "fulfillListing", tokenId, seller, paymentToken, priceWei },
|
|
6743
|
+
`ContinuumDAO marketplace: buy veCTM #${tokenId.toString()}.`,
|
|
6744
|
+
{ seller, paymentToken }
|
|
6745
|
+
);
|
|
6746
|
+
}
|
|
6747
|
+
async function buildEvmMultisignBodyContinuumDaoMarketplaceCreateOffering(args) {
|
|
6748
|
+
const tokenId = parseTokenId2(args.tokenId);
|
|
6749
|
+
const paymentToken = viem.getAddress(args.paymentToken);
|
|
6750
|
+
const bidWei = parseWei(args.bidWei, "Bid");
|
|
6751
|
+
const deadline = parseWei(args.deadline, "Deadline");
|
|
6752
|
+
return build(
|
|
6753
|
+
args,
|
|
6754
|
+
{ action: "createOffering", tokenId, paymentToken, bidWei, deadline },
|
|
6755
|
+
`ContinuumDAO marketplace: offer on veCTM #${tokenId.toString()}.`,
|
|
6756
|
+
{ paymentToken }
|
|
6757
|
+
);
|
|
6758
|
+
}
|
|
6759
|
+
async function buildEvmMultisignBodyContinuumDaoMarketplaceRescind(args) {
|
|
6760
|
+
const tokenId = parseTokenId2(args.tokenId);
|
|
6761
|
+
return build(
|
|
6762
|
+
args,
|
|
6763
|
+
{ action: "rescind", tokenId },
|
|
6764
|
+
`ContinuumDAO marketplace: rescind offer on veCTM #${tokenId.toString()}.`,
|
|
6765
|
+
{}
|
|
6766
|
+
);
|
|
6767
|
+
}
|
|
6768
|
+
async function buildEvmMultisignBodyContinuumDaoMarketplaceFulfillOffering(args) {
|
|
6769
|
+
const tokenId = parseTokenId2(args.tokenId);
|
|
6770
|
+
const buyer = viem.getAddress(args.buyer);
|
|
6771
|
+
const paymentToken = viem.getAddress(args.paymentToken);
|
|
6772
|
+
const priceWei = parseWei(args.priceWei, "Price");
|
|
6773
|
+
return build(
|
|
6774
|
+
args,
|
|
6775
|
+
{ action: "fulfillOffering", tokenId, buyer, paymentToken, priceWei },
|
|
6776
|
+
`ContinuumDAO marketplace: accept offer on veCTM #${tokenId.toString()}.`,
|
|
6777
|
+
{ buyer, paymentToken }
|
|
6778
|
+
);
|
|
6779
|
+
}
|
|
6780
|
+
async function buildEvmMultisignBodyContinuumDaoMarketplaceCreateAuction(args) {
|
|
6781
|
+
const tokenId = parseTokenId2(args.tokenId);
|
|
6782
|
+
const paymentToken = viem.getAddress(args.paymentToken);
|
|
6783
|
+
const deadline = parseWei(args.deadline, "Deadline");
|
|
6784
|
+
const reserveWei = parseWei(args.reserveWei, "Reserve");
|
|
6785
|
+
const minIncrementWei = parseWei(args.minIncrementWei, "Minimum increment");
|
|
6786
|
+
return build(
|
|
6787
|
+
args,
|
|
6788
|
+
{ action: "createAuction", tokenId, paymentToken, deadline, reserveWei, minIncrementWei },
|
|
6789
|
+
`ContinuumDAO marketplace: auction veCTM #${tokenId.toString()}.`,
|
|
6790
|
+
{ paymentToken }
|
|
6791
|
+
);
|
|
6792
|
+
}
|
|
6793
|
+
async function buildEvmMultisignBodyContinuumDaoMarketplaceCancelAuction(args) {
|
|
6794
|
+
const tokenId = parseTokenId2(args.tokenId);
|
|
6795
|
+
return build(
|
|
6796
|
+
args,
|
|
6797
|
+
{ action: "cancelAuction", tokenId },
|
|
6798
|
+
`ContinuumDAO marketplace: cancel auction for veCTM #${tokenId.toString()}.`,
|
|
6799
|
+
{}
|
|
6800
|
+
);
|
|
6801
|
+
}
|
|
6802
|
+
async function buildEvmMultisignBodyContinuumDaoMarketplaceAuctionBid(args) {
|
|
6803
|
+
const tokenId = parseTokenId2(args.tokenId);
|
|
6804
|
+
const seller = viem.getAddress(args.seller);
|
|
6805
|
+
const priceWei = parseWei(args.priceWei, "Bid");
|
|
6806
|
+
return build(
|
|
6807
|
+
args,
|
|
6808
|
+
{ action: "auctionBid", tokenId, seller, priceWei },
|
|
6809
|
+
`ContinuumDAO marketplace: bid on veCTM #${tokenId.toString()}.`,
|
|
6810
|
+
{ seller }
|
|
6811
|
+
);
|
|
6812
|
+
}
|
|
6813
|
+
async function buildEvmMultisignBodyContinuumDaoMarketplaceSettleAuction(args) {
|
|
6814
|
+
const tokenId = parseTokenId2(args.tokenId);
|
|
6815
|
+
const seller = viem.getAddress(args.seller);
|
|
6816
|
+
return build(
|
|
6817
|
+
args,
|
|
6818
|
+
{ action: "settleAuction", tokenId, seller },
|
|
6819
|
+
`ContinuumDAO marketplace: settle auction for veCTM #${tokenId.toString()}.`,
|
|
6820
|
+
{ seller }
|
|
6821
|
+
);
|
|
6822
|
+
}
|
|
6823
|
+
function parseExtra(detail) {
|
|
6824
|
+
const raw = detail?.ExtraJSON ?? detail?.extraJSON;
|
|
6825
|
+
if (raw == null) return null;
|
|
6826
|
+
if (typeof raw === "object" && !Array.isArray(raw)) return raw;
|
|
6827
|
+
if (typeof raw === "string" && raw.trim()) {
|
|
6828
|
+
try {
|
|
6829
|
+
const parsed = JSON.parse(raw);
|
|
6830
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
|
|
6831
|
+
} catch {
|
|
6832
|
+
return null;
|
|
6833
|
+
}
|
|
6834
|
+
}
|
|
6835
|
+
return null;
|
|
6836
|
+
}
|
|
6837
|
+
function same4(a, b) {
|
|
6838
|
+
try {
|
|
6839
|
+
return viem.getAddress(a) === viem.getAddress(b);
|
|
6840
|
+
} catch {
|
|
6841
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
6842
|
+
}
|
|
6843
|
+
}
|
|
6844
|
+
function marketplaceVeCtmReceivedBy(detail, executor) {
|
|
6845
|
+
const extra = parseExtra(detail);
|
|
6846
|
+
const batch = extra?.batchMeta;
|
|
6847
|
+
if (!Array.isArray(batch) || !executor.trim()) return null;
|
|
6848
|
+
for (const entry of batch) {
|
|
6849
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
6850
|
+
const row = entry;
|
|
6851
|
+
const evm = row.evm;
|
|
6852
|
+
const type = evm && typeof evm === "object" ? String(evm.type ?? "") : "";
|
|
6853
|
+
const meta4 = row.continuumDaoMarketplace;
|
|
6854
|
+
if (!meta4 || typeof meta4 !== "object" || Array.isArray(meta4)) continue;
|
|
6855
|
+
const info = meta4;
|
|
6856
|
+
const tokenId = String(info.tokenId ?? "").trim();
|
|
6857
|
+
if (!tokenId) continue;
|
|
6858
|
+
if (type === "continuum_dao_marketplace_fulfill_listing") {
|
|
6859
|
+
const recipient = String(info.recipient ?? "");
|
|
6860
|
+
if (!recipient || same4(recipient, executor)) return { tokenId };
|
|
6861
|
+
}
|
|
6862
|
+
if (type === "continuum_dao_marketplace_settle_auction") {
|
|
6863
|
+
const highest = String(info.highestBidder ?? "");
|
|
6864
|
+
const recipient = String(info.recipient ?? "");
|
|
6865
|
+
if (highest && same4(highest, executor) && same4(recipient, executor)) return { tokenId };
|
|
6866
|
+
}
|
|
6867
|
+
}
|
|
6868
|
+
return null;
|
|
6869
|
+
}
|
|
6870
|
+
|
|
6871
|
+
// src/protocols/evm/continuum-dao/index.ts
|
|
6872
|
+
registerProtocolModule(continuumDaoMarketplaceProtocolModule);
|
|
4716
6873
|
var continuumDaoProtocolModule = {
|
|
4717
6874
|
id: exports.CONTINUUM_DAO_PROTOCOL_ID,
|
|
4718
6875
|
chainCategory: "evm",
|
|
@@ -4765,6 +6922,7 @@ var continuumDaoProtocolModule = {
|
|
|
4765
6922
|
registerProtocolModule(continuumDaoProtocolModule);
|
|
4766
6923
|
|
|
4767
6924
|
exports.ATTACH_VECTM_SIGNATURE = ATTACH_VECTM_SIGNATURE;
|
|
6925
|
+
exports.AUCTION_STATUS = AUCTION_STATUS;
|
|
4768
6926
|
exports.BRAVO_SUPPORT_LABELS = BRAVO_SUPPORT_LABELS;
|
|
4769
6927
|
exports.CONTINUUM_DAO_APPROVE_FALLBACK = CONTINUUM_DAO_APPROVE_FALLBACK;
|
|
4770
6928
|
exports.CONTINUUM_DAO_ATTACH_FALLBACK = CONTINUUM_DAO_ATTACH_FALLBACK;
|
|
@@ -4779,11 +6937,22 @@ exports.CONTINUUM_DAO_MERGE_FALLBACK = CONTINUUM_DAO_MERGE_FALLBACK;
|
|
|
4779
6937
|
exports.CONTINUUM_DAO_SPLIT_FALLBACK = CONTINUUM_DAO_SPLIT_FALLBACK;
|
|
4780
6938
|
exports.CONTINUUM_DAO_TRANSFER_FALLBACK = CONTINUUM_DAO_TRANSFER_FALLBACK;
|
|
4781
6939
|
exports.CONTINUUM_DAO_WITHDRAW_FALLBACK = CONTINUUM_DAO_WITHDRAW_FALLBACK;
|
|
6940
|
+
exports.FEE_TIER_NAMES = FEE_TIER_NAMES;
|
|
4782
6941
|
exports.INCREASE_UNLOCK_TIME_SIGNATURE = INCREASE_UNLOCK_TIME_SIGNATURE;
|
|
6942
|
+
exports.MARKETPLACE_APPROVE_FALLBACK = MARKETPLACE_APPROVE_FALLBACK;
|
|
6943
|
+
exports.MARKETPLACE_AUCTION_CREATE_FALLBACK = MARKETPLACE_AUCTION_CREATE_FALLBACK;
|
|
6944
|
+
exports.MARKETPLACE_BID_FALLBACK = MARKETPLACE_BID_FALLBACK;
|
|
6945
|
+
exports.MARKETPLACE_FULFILL_FALLBACK = MARKETPLACE_FULFILL_FALLBACK;
|
|
6946
|
+
exports.MARKETPLACE_LISTING_FALLBACK = MARKETPLACE_LISTING_FALLBACK;
|
|
6947
|
+
exports.MARKETPLACE_OFFERING_FALLBACK = MARKETPLACE_OFFERING_FALLBACK;
|
|
6948
|
+
exports.MARKETPLACE_SETTLE_FALLBACK = MARKETPLACE_SETTLE_FALLBACK;
|
|
6949
|
+
exports.MARKET_ORDER_STATUS = MARKET_ORDER_STATUS;
|
|
4783
6950
|
exports.VECTM_NODE_INFO_TUPLE = VECTM_NODE_INFO_TUPLE;
|
|
4784
6951
|
exports.VOTE_CAST_EVENT = VOTE_CAST_EVENT;
|
|
4785
6952
|
exports.VOTE_CAST_WITH_PARAMS_EVENT = VOTE_CAST_WITH_PARAMS_EVENT;
|
|
6953
|
+
exports.applyDerivedStatuses = applyDerivedStatuses;
|
|
4786
6954
|
exports.applyForumSectionCheck = applyForumSectionCheck;
|
|
6955
|
+
exports.applyMarketplaceEvent = applyMarketplaceEvent;
|
|
4787
6956
|
exports.applyNodeAttachments = applyNodeAttachments;
|
|
4788
6957
|
exports.assertContinuumDaoForumDeleteInput = assertContinuumDaoForumDeleteInput;
|
|
4789
6958
|
exports.assertContinuumDaoForumMarkReadInput = assertContinuumDaoForumMarkReadInput;
|
|
@@ -4804,6 +6973,8 @@ exports.assertSplitExtracted = assertSplitExtracted;
|
|
|
4804
6973
|
exports.assertTransfer = assertTransfer;
|
|
4805
6974
|
exports.assertUndelegateNotAlreadySelf = assertUndelegateNotAlreadySelf;
|
|
4806
6975
|
exports.assertWithdraw = assertWithdraw;
|
|
6976
|
+
exports.auctionCandidate = auctionCandidate;
|
|
6977
|
+
exports.auctionStatusName = auctionStatusName;
|
|
4807
6978
|
exports.bravoSupportLabel = bravoSupportLabel;
|
|
4808
6979
|
exports.bucketGovernorState = bucketGovernorState;
|
|
4809
6980
|
exports.buildBravoProposalArgs = buildBravoProposalArgs;
|
|
@@ -4821,6 +6992,16 @@ exports.buildEvmMultisignBodyContinuumDaoForumSignIn = buildEvmMultisignBodyCont
|
|
|
4821
6992
|
exports.buildEvmMultisignBodyContinuumDaoIncreaseAmount = buildEvmMultisignBodyContinuumDaoIncreaseAmount;
|
|
4822
6993
|
exports.buildEvmMultisignBodyContinuumDaoIncreaseUnlockTime = buildEvmMultisignBodyContinuumDaoIncreaseUnlockTime;
|
|
4823
6994
|
exports.buildEvmMultisignBodyContinuumDaoLiquidate = buildEvmMultisignBodyContinuumDaoLiquidate;
|
|
6995
|
+
exports.buildEvmMultisignBodyContinuumDaoMarketplaceAuctionBid = buildEvmMultisignBodyContinuumDaoMarketplaceAuctionBid;
|
|
6996
|
+
exports.buildEvmMultisignBodyContinuumDaoMarketplaceCancelAuction = buildEvmMultisignBodyContinuumDaoMarketplaceCancelAuction;
|
|
6997
|
+
exports.buildEvmMultisignBodyContinuumDaoMarketplaceCreateAuction = buildEvmMultisignBodyContinuumDaoMarketplaceCreateAuction;
|
|
6998
|
+
exports.buildEvmMultisignBodyContinuumDaoMarketplaceCreateListing = buildEvmMultisignBodyContinuumDaoMarketplaceCreateListing;
|
|
6999
|
+
exports.buildEvmMultisignBodyContinuumDaoMarketplaceCreateOffering = buildEvmMultisignBodyContinuumDaoMarketplaceCreateOffering;
|
|
7000
|
+
exports.buildEvmMultisignBodyContinuumDaoMarketplaceDelist = buildEvmMultisignBodyContinuumDaoMarketplaceDelist;
|
|
7001
|
+
exports.buildEvmMultisignBodyContinuumDaoMarketplaceFulfillListing = buildEvmMultisignBodyContinuumDaoMarketplaceFulfillListing;
|
|
7002
|
+
exports.buildEvmMultisignBodyContinuumDaoMarketplaceFulfillOffering = buildEvmMultisignBodyContinuumDaoMarketplaceFulfillOffering;
|
|
7003
|
+
exports.buildEvmMultisignBodyContinuumDaoMarketplaceRescind = buildEvmMultisignBodyContinuumDaoMarketplaceRescind;
|
|
7004
|
+
exports.buildEvmMultisignBodyContinuumDaoMarketplaceSettleAuction = buildEvmMultisignBodyContinuumDaoMarketplaceSettleAuction;
|
|
4824
7005
|
exports.buildEvmMultisignBodyContinuumDaoMerge = buildEvmMultisignBodyContinuumDaoMerge;
|
|
4825
7006
|
exports.buildEvmMultisignBodyContinuumDaoProposeBravo = buildEvmMultisignBodyContinuumDaoProposeBravo;
|
|
4826
7007
|
exports.buildEvmMultisignBodyContinuumDaoProposeDelta = buildEvmMultisignBodyContinuumDaoProposeDelta;
|
|
@@ -4830,7 +7011,9 @@ exports.buildEvmMultisignBodyContinuumDaoSplit = buildEvmMultisignBodyContinuumD
|
|
|
4830
7011
|
exports.buildEvmMultisignBodyContinuumDaoTransfer = buildEvmMultisignBodyContinuumDaoTransfer;
|
|
4831
7012
|
exports.buildEvmMultisignBodyContinuumDaoUndelegate = buildEvmMultisignBodyContinuumDaoUndelegate;
|
|
4832
7013
|
exports.buildEvmMultisignBodyContinuumDaoWithdraw = buildEvmMultisignBodyContinuumDaoWithdraw;
|
|
7014
|
+
exports.buildFeeAlternativeSummary = buildFeeAlternativeSummary;
|
|
4833
7015
|
exports.buildFoundryProposalSimulatePlan = buildFoundryProposalSimulatePlan;
|
|
7016
|
+
exports.calculateMarketplaceFee = calculateMarketplaceFee;
|
|
4834
7017
|
exports.collectVotesFromLogs = collectVotesFromLogs;
|
|
4835
7018
|
exports.computeLiquidationAmounts = computeLiquidationAmounts;
|
|
4836
7019
|
exports.continuumDaoComposeProposalAction = continuumDaoComposeProposalAction;
|
|
@@ -4867,6 +7050,7 @@ exports.continuumDaoForumUnread = continuumDaoForumUnread;
|
|
|
4867
7050
|
exports.continuumDaoForumUrl = continuumDaoForumUrl;
|
|
4868
7051
|
exports.continuumDaoForumUserPostIds = continuumDaoForumUserPostIds;
|
|
4869
7052
|
exports.continuumDaoHashProposal = continuumDaoHashProposal;
|
|
7053
|
+
exports.continuumDaoMarketplaceProtocolModule = continuumDaoMarketplaceProtocolModule;
|
|
4870
7054
|
exports.continuumDaoMpaFlag = continuumDaoMpaFlag;
|
|
4871
7055
|
exports.continuumDaoMpaListing = continuumDaoMpaListing;
|
|
4872
7056
|
exports.continuumDaoMpaMailboxList = continuumDaoMpaMailboxList;
|
|
@@ -4880,6 +7064,8 @@ exports.continuumDaoSimulateProposal = continuumDaoSimulateProposal;
|
|
|
4880
7064
|
exports.continuumDaoTechnocoreBind = continuumDaoTechnocoreBind;
|
|
4881
7065
|
exports.ctmTokenAddressOnEvmChain = ctmTokenAddressOnEvmChain;
|
|
4882
7066
|
exports.decodeDeltaVoteParams = decodeDeltaVoteParams;
|
|
7067
|
+
exports.deriveAuctionStatus = deriveAuctionStatus;
|
|
7068
|
+
exports.emptyMarketplaceIndexCache = emptyMarketplaceIndexCache;
|
|
4883
7069
|
exports.encodeContinuumDaoNodeInfo = encodeContinuumDaoNodeInfo;
|
|
4884
7070
|
exports.encodeDeltaMetadata = encodeDeltaMetadata;
|
|
4885
7071
|
exports.encodeDeltaVoteParams = encodeDeltaVoteParams;
|
|
@@ -4890,10 +7076,19 @@ exports.expectedForumSectionForProposalType = expectedForumSectionForProposalTyp
|
|
|
4890
7076
|
exports.explainGovAction = explainGovAction;
|
|
4891
7077
|
exports.explainProposalRecord = explainProposalRecord;
|
|
4892
7078
|
exports.explorerBase = explorerBase;
|
|
7079
|
+
exports.fetchContinuumDaoMarketplaceActivity = fetchContinuumDaoMarketplaceActivity;
|
|
7080
|
+
exports.fetchContinuumDaoMarketplaceAuctions = fetchContinuumDaoMarketplaceAuctions;
|
|
7081
|
+
exports.fetchContinuumDaoMarketplaceConfig = fetchContinuumDaoMarketplaceConfig;
|
|
7082
|
+
exports.fetchContinuumDaoMarketplaceFeePreview = fetchContinuumDaoMarketplaceFeePreview;
|
|
7083
|
+
exports.fetchContinuumDaoMarketplaceListings = fetchContinuumDaoMarketplaceListings;
|
|
7084
|
+
exports.fetchContinuumDaoMarketplaceOfferings = fetchContinuumDaoMarketplaceOfferings;
|
|
7085
|
+
exports.fetchContinuumDaoMarketplaceToken = fetchContinuumDaoMarketplaceToken;
|
|
4893
7086
|
exports.floorUnlockTimeSeconds = floorUnlockTimeSeconds;
|
|
7087
|
+
exports.foldMarketplaceEvents = foldMarketplaceEvents;
|
|
4894
7088
|
exports.formatProposalSimulationFailure = formatProposalSimulationFailure;
|
|
4895
7089
|
exports.foundryPlanHasSequentialExecute = foundryPlanHasSequentialExecute;
|
|
4896
7090
|
exports.foundryScriptContainsCall = foundryScriptContainsCall;
|
|
7091
|
+
exports.getMarketplaceIndexMemoryCache = getMarketplaceIndexMemoryCache;
|
|
4897
7092
|
exports.governorAddressOnEvmChain = governorAddressOnEvmChain;
|
|
4898
7093
|
exports.howVoted = howVoted;
|
|
4899
7094
|
exports.isConfiguredAddress = isConfiguredAddress;
|
|
@@ -4907,14 +7102,25 @@ exports.isForumIdeaSection = isForumIdeaSection;
|
|
|
4907
7102
|
exports.isGovNoOpAction = isGovNoOpAction;
|
|
4908
7103
|
exports.isLegacyContinuumDaoGovernor = isLegacyContinuumDaoGovernor;
|
|
4909
7104
|
exports.isLineaHomeNetwork = isLineaHomeNetwork;
|
|
7105
|
+
exports.isLiveAuctionStatus = isLiveAuctionStatus;
|
|
7106
|
+
exports.isOpenOrder = isOpenOrder;
|
|
4910
7107
|
exports.isRemoteC3Action = isRemoteC3Action;
|
|
4911
7108
|
exports.isVotingEscrowContinuumName = isVotingEscrowContinuumName;
|
|
7109
|
+
exports.keyGenOwnsVeCtm = keyGenOwnsVeCtm;
|
|
4912
7110
|
exports.listContinuumDaoDefaultAssets = listContinuumDaoDefaultAssets;
|
|
7111
|
+
exports.listingCandidate = listingCandidate;
|
|
7112
|
+
exports.loadMarketplacePlanSnapshot = loadMarketplacePlanSnapshot;
|
|
4913
7113
|
exports.looksLikeProposalCatalogId = looksLikeProposalCatalogId;
|
|
4914
7114
|
exports.looksLikeUnixSeconds = looksLikeUnixSeconds;
|
|
7115
|
+
exports.marketplacePublicClient = marketplacePublicClient;
|
|
7116
|
+
exports.marketplaceVeCtmReceivedBy = marketplaceVeCtmReceivedBy;
|
|
4915
7117
|
exports.maxLockDurationSeconds = maxLockDurationSeconds;
|
|
7118
|
+
exports.monthsOfFees = monthsOfFees;
|
|
4916
7119
|
exports.normalizeGovConfiguration = normalizeGovConfiguration;
|
|
4917
7120
|
exports.normalizeNodeInfo = normalizeNodeInfo;
|
|
7121
|
+
exports.orderStatusName = orderStatusName;
|
|
7122
|
+
exports.pickFeeAlternativeExample = pickFeeAlternativeExample;
|
|
7123
|
+
exports.planMarketplaceSteps = planMarketplaceSteps;
|
|
4918
7124
|
exports.preflightAttachVeCtm = preflightAttachVeCtm;
|
|
4919
7125
|
exports.preflightCreateLock = preflightCreateLock;
|
|
4920
7126
|
exports.preflightDelegate = preflightDelegate;
|
|
@@ -4929,18 +7135,27 @@ exports.preflightUndelegate = preflightUndelegate;
|
|
|
4929
7135
|
exports.preflightWithdraw = preflightWithdraw;
|
|
4930
7136
|
exports.proposalDescriptionHash = proposalDescriptionHash;
|
|
4931
7137
|
exports.publicClient = publicClient2;
|
|
7138
|
+
exports.quoteContinuumDaoMarketplaceFeeAlternative = quoteContinuumDaoMarketplaceFeeAlternative;
|
|
7139
|
+
exports.rankMarketplaceSearchHits = rankMarketplaceSearchHits;
|
|
4932
7140
|
exports.readCtmBalanceWei = readCtmBalanceWei;
|
|
7141
|
+
exports.readMarketplaceConfigFromChain = readMarketplaceConfigFromChain;
|
|
7142
|
+
exports.readMarketplaceFeePreviewFromChain = readMarketplaceFeePreviewFromChain;
|
|
4933
7143
|
exports.readMinimumLockWei = readMinimumLockWei;
|
|
4934
7144
|
exports.readVeCtmLockState = readVeCtmLockState;
|
|
4935
7145
|
exports.requireGovernor = requireGovernor;
|
|
4936
7146
|
exports.resolveAttachGroupId = resolveAttachGroupId;
|
|
4937
7147
|
exports.resolveGovernorProposalRef = resolveGovernorProposalRef;
|
|
4938
7148
|
exports.resolveProposalCatalogRange = resolveProposalCatalogRange;
|
|
7149
|
+
exports.scanMarketplaceLogs = scanMarketplaceLogs;
|
|
7150
|
+
exports.searchContinuumDaoMarketplace = searchContinuumDaoMarketplace;
|
|
7151
|
+
exports.setMarketplaceIndexMemoryCache = setMarketplaceIndexMemoryCache;
|
|
4939
7152
|
exports.summarizeLiveProposals = summarizeLiveProposals;
|
|
4940
7153
|
exports.summarizeProposalVotes = summarizeProposalVotes;
|
|
4941
7154
|
exports.throwIfProposalSimulationFailed = throwIfProposalSimulationFailed;
|
|
4942
7155
|
exports.validateAbiParameter = validateAbiParameter;
|
|
4943
7156
|
exports.votingEscrowAddressOnEvmChain = votingEscrowAddressOnEvmChain;
|
|
7157
|
+
exports.votingEscrowMarketplaceAddressOnEvmChain = votingEscrowMarketplaceAddressOnEvmChain;
|
|
7158
|
+
exports.votingPowerAboveUntil = votingPowerAboveUntil;
|
|
4944
7159
|
exports.votingPowerRefuse = votingPowerRefuse;
|
|
4945
7160
|
exports.votingPowerWarning = votingPowerWarning;
|
|
4946
7161
|
//# sourceMappingURL=index.cjs.map
|