@ocap/util 1.30.26 → 1.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/amm.d.mts +158 -0
- package/esm/amm.mjs +269 -0
- package/esm/arcade.d.mts +217 -0
- package/esm/arcade.mjs +484 -0
- package/esm/bonding-reserve-aup.d.mts +125 -0
- package/esm/bonding-reserve-aup.mjs +230 -0
- package/esm/composable-container.d.mts +141 -0
- package/esm/composable-container.mjs +264 -0
- package/esm/conditional-market.d.mts +151 -0
- package/esm/conditional-market.mjs +376 -0
- package/esm/curve.d.mts +43 -5
- package/esm/curve.mjs +71 -9
- package/esm/foreign-receipt.d.mts +126 -0
- package/esm/foreign-receipt.mjs +388 -0
- package/esm/index.d.mts +8 -1
- package/esm/index.mjs +8 -1
- package/esm/node_modules/@noble/hashes/_md.mjs +168 -0
- package/esm/node_modules/@noble/hashes/sha2.mjs +185 -0
- package/esm/node_modules/@noble/hashes/utils.mjs +175 -0
- package/lib/amm.cjs +279 -0
- package/lib/amm.d.cts +158 -0
- package/lib/arcade.cjs +491 -0
- package/lib/arcade.d.cts +217 -0
- package/lib/bonding-reserve-aup.cjs +232 -0
- package/lib/bonding-reserve-aup.d.cts +125 -0
- package/lib/composable-container.cjs +270 -0
- package/lib/composable-container.d.cts +141 -0
- package/lib/conditional-market.cjs +377 -0
- package/lib/conditional-market.d.cts +151 -0
- package/lib/curve.cjs +73 -9
- package/lib/curve.d.cts +43 -5
- package/lib/foreign-receipt.cjs +396 -0
- package/lib/foreign-receipt.d.cts +126 -0
- package/lib/index.cjs +57 -1
- package/lib/index.d.cts +8 -1
- package/lib/node_modules/@noble/hashes/_md.cjs +171 -0
- package/lib/node_modules/@noble/hashes/sha2.cjs +185 -0
- package/lib/node_modules/@noble/hashes/utils.cjs +183 -0
- package/package.json +2 -2
package/esm/curve.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { BN } from "./bn.mjs";
|
|
2
|
+
import { toBN } from "./index.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/curve.ts
|
|
4
5
|
const ZERO = new BN(0);
|
|
6
|
+
const ONE = new BN(1);
|
|
5
7
|
const TWO = new BN(2);
|
|
6
8
|
const THREE = new BN(3);
|
|
7
9
|
const TEN = new BN(10);
|
|
@@ -11,9 +13,14 @@ let Direction = /* @__PURE__ */ function(Direction$1) {
|
|
|
11
13
|
return Direction$1;
|
|
12
14
|
}({});
|
|
13
15
|
function getDecimalFactor(decimal) {
|
|
14
|
-
if (!Number.isInteger(decimal) || decimal
|
|
16
|
+
if (!Number.isInteger(decimal) || decimal < 0 || decimal > 78) throw new Error("INVALID_DECIMAL_FACTOR");
|
|
15
17
|
return TEN.pow(new BN(decimal));
|
|
16
18
|
}
|
|
19
|
+
function divByDirection(numerator, denominator, direction) {
|
|
20
|
+
if (numerator.isZero()) return ZERO;
|
|
21
|
+
if (direction === Direction.Mint) return numerator.add(denominator).sub(ONE).div(denominator);
|
|
22
|
+
return numerator.div(denominator);
|
|
23
|
+
}
|
|
17
24
|
function assertValidDirection(direction) {
|
|
18
25
|
if (direction !== Direction.Mint && direction !== Direction.Burn) throw new Error("INVALID_DIRECTION");
|
|
19
26
|
}
|
|
@@ -51,7 +58,7 @@ function calcConstantCost({ amount, fixedPrice, decimal, direction = Direction.M
|
|
|
51
58
|
direction
|
|
52
59
|
});
|
|
53
60
|
if (amountBN.isZero()) return ZERO;
|
|
54
|
-
return amountBN.mul(priceBN)
|
|
61
|
+
return divByDirection(amountBN.mul(priceBN), decimalFactor, direction);
|
|
55
62
|
}
|
|
56
63
|
/**
|
|
57
64
|
* linear Curve
|
|
@@ -92,9 +99,10 @@ function calcLinearCost(params) {
|
|
|
92
99
|
if (params.direction === Direction.Burn && amount.gt(currentSupply)) throw new Error("SUPPLY_INSUFFICIENT");
|
|
93
100
|
if (amount.isZero()) return ZERO;
|
|
94
101
|
const integralDelta = params.direction === Direction.Mint ? amount.mul(currentSupply.mul(TWO).add(amount)) : amount.mul(currentSupply.mul(TWO).sub(amount));
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
|
|
102
|
+
const denominator = TWO.mul(decimalFactor.sqr());
|
|
103
|
+
const linearNumerator = TWO.mul(decimalFactor).mul(basePrice).mul(amount);
|
|
104
|
+
const integralNumerator = slope.mul(integralDelta);
|
|
105
|
+
return divByDirection(linearNumerator.add(integralNumerator), denominator, params.direction);
|
|
98
106
|
}
|
|
99
107
|
/**
|
|
100
108
|
* Quadratic Curve
|
|
@@ -142,9 +150,8 @@ function calcQuadraticCost(params) {
|
|
|
142
150
|
const sumSquaresAndProduct = newSupply.sqr().add(newSupply.mul(currentSupply)).add(currentSupply.sqr());
|
|
143
151
|
const cubicDelta = diff.mul(sumSquaresAndProduct);
|
|
144
152
|
const denom = THREE.mul(constant).mul(decimalFactor.sqr());
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
return cubicCost.add(linearCost);
|
|
153
|
+
const linearNumerator = THREE.mul(constant).mul(decimalFactor).mul(basePrice).mul(amount);
|
|
154
|
+
return divByDirection(cubicDelta.add(linearNumerator), denom, params.direction);
|
|
148
155
|
}
|
|
149
156
|
function calcFee({ reserveAmount, feeRate }) {
|
|
150
157
|
const reserveBN = new BN(reserveAmount);
|
|
@@ -200,6 +207,61 @@ function calcCost({ amount, decimal, currentSupply, direction, curve }) {
|
|
|
200
207
|
if (!calculator) throw new Error("INVALID_CURVE_TYPE");
|
|
201
208
|
return calculator();
|
|
202
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* 3-Token Model Prepaid Quota Minting & Revenue Split (#1168).
|
|
212
|
+
*
|
|
213
|
+
* Separates ABT reserve payment for consumable `Quota` (CreditToken) from `ArcKey` (BondingCurveToken)
|
|
214
|
+
* reserve pool so service consumption never drains the bonding curve redemption reserve.
|
|
215
|
+
*/
|
|
216
|
+
function calcQuotaMintFromPayment(params) {
|
|
217
|
+
const reservePaid = toBN(params.reservePaid);
|
|
218
|
+
const unitPrice = toBN(params.unitPrice);
|
|
219
|
+
const decimal = params.decimal ?? 2;
|
|
220
|
+
const creatorFeeBps = params.creatorFeeBps ?? 9500;
|
|
221
|
+
const protocolFeeBps = params.protocolFeeBps ?? 500;
|
|
222
|
+
if (reservePaid.lte(ZERO)) throw new Error("INVALID_RESERVE_AMOUNT");
|
|
223
|
+
if (unitPrice.lte(ZERO)) throw new Error("INVALID_PRICE");
|
|
224
|
+
if (!Number.isInteger(decimal) || decimal < 0 || decimal > 18) throw new Error("INVALID_DECIMAL");
|
|
225
|
+
if (!Number.isInteger(creatorFeeBps) || !Number.isInteger(protocolFeeBps) || creatorFeeBps < 0 || protocolFeeBps < 0 || creatorFeeBps + protocolFeeBps > 1e4) throw new Error("INVALID_FEE_RATE");
|
|
226
|
+
const decimalFactor = TEN.pow(new BN(decimal));
|
|
227
|
+
const quotaMinted = reservePaid.mul(decimalFactor).div(unitPrice);
|
|
228
|
+
if (quotaMinted.lte(ZERO)) throw new Error("INSUFFICIENT_PAYMENT_FOR_QUOTA");
|
|
229
|
+
const effectiveReserveCost = divByDirection(quotaMinted.mul(unitPrice), decimalFactor, Direction.Mint);
|
|
230
|
+
const refundReserve = reservePaid.sub(effectiveReserveCost);
|
|
231
|
+
const bpsDenom = new BN(1e4);
|
|
232
|
+
const protocolFee = effectiveReserveCost.mul(new BN(protocolFeeBps)).div(bpsDenom);
|
|
233
|
+
const creatorRevenue = effectiveReserveCost.mul(new BN(creatorFeeBps)).div(bpsDenom);
|
|
234
|
+
return {
|
|
235
|
+
quotaMinted,
|
|
236
|
+
effectiveReserveCost,
|
|
237
|
+
refundReserve,
|
|
238
|
+
creatorRevenue,
|
|
239
|
+
protocolFee,
|
|
240
|
+
serviceEscrow: effectiveReserveCost.sub(protocolFee).sub(creatorRevenue)
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* 3-Token Model Prepaid Quota Consumption & ArcKey Gating Check (#1168).
|
|
245
|
+
*
|
|
246
|
+
* Verifies the caller holds the required indivisible `ArcKey` balance (without burning `ArcKey`),
|
|
247
|
+
* enforces `Quota` expiration, and burns `consumeAmount` of prepaid `Quota`.
|
|
248
|
+
*/
|
|
249
|
+
function consumePrepaidQuota(params) {
|
|
250
|
+
const availableQuota = toBN(params.availableQuota);
|
|
251
|
+
const consumeAmount = toBN(params.consumeAmount);
|
|
252
|
+
const userArcKeyBalance = toBN(params.userArcKeyBalance ?? 1);
|
|
253
|
+
const minArcKeyBalance = toBN(params.minArcKeyBalance ?? 1);
|
|
254
|
+
if (availableQuota.lt(ZERO)) throw new Error("INVALID_QUOTA_BALANCE");
|
|
255
|
+
if (consumeAmount.lte(ZERO)) throw new Error("INVALID_CONSUME_AMOUNT");
|
|
256
|
+
if (userArcKeyBalance.lt(minArcKeyBalance)) throw new Error("INSUFFICIENT_ARCKEY_PASS");
|
|
257
|
+
if (typeof params.expiresAt === "number" && params.expiresAt > 0 && typeof params.now === "number" && params.now > params.expiresAt) throw new Error("QUOTA_EXPIRED");
|
|
258
|
+
if (availableQuota.lt(consumeAmount)) throw new Error("INSUFFICIENT_QUOTA");
|
|
259
|
+
return {
|
|
260
|
+
burnedQuota: consumeAmount,
|
|
261
|
+
remainingQuota: availableQuota.sub(consumeAmount),
|
|
262
|
+
arcKeyBalanceAfter: userArcKeyBalance
|
|
263
|
+
};
|
|
264
|
+
}
|
|
203
265
|
|
|
204
266
|
//#endregion
|
|
205
|
-
export { Direction, calcConstantCost, calcConstantPrice, calcCost, calcFee, calcLinearCost, calcLinearPrice, calcPrice, calcQuadraticCost, calcQuadraticPrice };
|
|
267
|
+
export { Direction, calcConstantCost, calcConstantPrice, calcCost, calcFee, calcLinearCost, calcLinearPrice, calcPrice, calcQuadraticCost, calcQuadraticPrice, calcQuotaMintFromPayment, consumePrepaidQuota };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
//#region src/foreign-receipt.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Pure-TS FIPS 180-4 SHA-256 implementation (uses `node:crypto` fast path when available).
|
|
4
|
+
*/
|
|
5
|
+
declare function sha256Hex(data: Uint8Array): string;
|
|
6
|
+
type ForeignReceiptStatus = 'PROVISIONAL' | 'FINAL' | 'REORG_CANCELLED';
|
|
7
|
+
interface ForeignQuoteSpec {
|
|
8
|
+
quoteId: string;
|
|
9
|
+
sourceChainId: string;
|
|
10
|
+
vaultAddress: string;
|
|
11
|
+
paymentToken: string;
|
|
12
|
+
paymentAmount: string | bigint;
|
|
13
|
+
targetChainId: string;
|
|
14
|
+
targetFactoryAddress: string;
|
|
15
|
+
buyerDid: string;
|
|
16
|
+
maxSlippageBps: number;
|
|
17
|
+
reserveBps: number;
|
|
18
|
+
expiresAt: number;
|
|
19
|
+
}
|
|
20
|
+
interface ForeignReceiptKey {
|
|
21
|
+
sourceChainId: string;
|
|
22
|
+
vaultAddress: string;
|
|
23
|
+
txHash: string;
|
|
24
|
+
eventIndex: number;
|
|
25
|
+
}
|
|
26
|
+
interface ForeignVaultSplitResult {
|
|
27
|
+
totalAmount: bigint;
|
|
28
|
+
reserveBucket: bigint;
|
|
29
|
+
protocolFeeBucket: bigint;
|
|
30
|
+
devBucket: bigint;
|
|
31
|
+
reserveBps: number;
|
|
32
|
+
protocolFeeBps: number;
|
|
33
|
+
}
|
|
34
|
+
interface ForeignReceiptRecord {
|
|
35
|
+
receiptId: string;
|
|
36
|
+
idempotencyKey: string;
|
|
37
|
+
quoteId: string;
|
|
38
|
+
quoteDigest: string;
|
|
39
|
+
sourceChainId: string;
|
|
40
|
+
vaultAddress: string;
|
|
41
|
+
txHash: string;
|
|
42
|
+
eventIndex: number;
|
|
43
|
+
buyerDid: string;
|
|
44
|
+
targetFactoryAddress: string;
|
|
45
|
+
paymentToken: string;
|
|
46
|
+
paymentAmount: string;
|
|
47
|
+
reserveBucket: string;
|
|
48
|
+
protocolFeeBucket: string;
|
|
49
|
+
devBucket: string;
|
|
50
|
+
status: ForeignReceiptStatus;
|
|
51
|
+
sourceBlockNumber?: number;
|
|
52
|
+
finalizedBlockNumber?: number;
|
|
53
|
+
reorgReason?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Validate a `ForeignQuoteSpec` and compute its deterministic canonical SHA-256 digest (`0x...`).
|
|
57
|
+
*/
|
|
58
|
+
declare function computeForeignQuoteDigest(quote: ForeignQuoteSpec, nowMs?: number): string;
|
|
59
|
+
/**
|
|
60
|
+
* Build the canonical 4-tuple idempotency key string `(sourceChainId, vaultAddress, txHash, eventIndex)`.
|
|
61
|
+
*/
|
|
62
|
+
declare function formatForeignReceiptKey(key: ForeignReceiptKey): string;
|
|
63
|
+
/**
|
|
64
|
+
* Compute a deterministic receipt ID (`0x...`) from the 4-tuple idempotency key.
|
|
65
|
+
*/
|
|
66
|
+
declare function computeForeignReceiptId(key: ForeignReceiptKey): string;
|
|
67
|
+
/**
|
|
68
|
+
* Deterministically split an external payment into `reserveBucket` (locked for floor/payout redemptions),
|
|
69
|
+
* `protocolFeeBucket`, and `devBucket` (studio revenue).
|
|
70
|
+
* Guarantees exact conservation: `reserveBucket + protocolFeeBucket + devBucket === totalAmount`.
|
|
71
|
+
*/
|
|
72
|
+
declare function splitForeignVaultPayment(paymentAmount: string | bigint, reserveBps: number, protocolFeeBps?: number): ForeignVaultSplitResult;
|
|
73
|
+
/**
|
|
74
|
+
* Check whether an asset minted via a `ForeignReceiptRecord` is unlocked for secondary transfer,
|
|
75
|
+
* floor burn redemption, or external payout.
|
|
76
|
+
* Assets minted under `PROVISIONAL` confirmation are locked until promoted to `FINAL`.
|
|
77
|
+
*/
|
|
78
|
+
declare function isAssetUnlockedByReceipt(record: Pick<ForeignReceiptRecord, 'status'>): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* In-memory deterministic registry for `ForeignReceipt` idempotency and two-stage (`PROVISIONAL -> FINAL`) finality.
|
|
81
|
+
*/
|
|
82
|
+
declare class ForeignReceiptRegistry {
|
|
83
|
+
private readonly byReceiptId;
|
|
84
|
+
private readonly byIdempotencyKey;
|
|
85
|
+
private readonly byQuoteId;
|
|
86
|
+
registerReceipt(params: {
|
|
87
|
+
key: ForeignReceiptKey;
|
|
88
|
+
quote: ForeignQuoteSpec;
|
|
89
|
+
status?: 'PROVISIONAL' | 'FINAL';
|
|
90
|
+
protocolFeeBps?: number;
|
|
91
|
+
sourceBlockNumber?: number;
|
|
92
|
+
nowMs?: number;
|
|
93
|
+
}): ForeignReceiptRecord;
|
|
94
|
+
promoteToFinal(receiptId: string, finalizedBlockNumber?: number): ForeignReceiptRecord;
|
|
95
|
+
markReorgCancelled(receiptId: string, reason: string): ForeignReceiptRecord;
|
|
96
|
+
getByReceiptId(receiptId: string): ForeignReceiptRecord | undefined;
|
|
97
|
+
hasIdempotencyKey(key: ForeignReceiptKey): boolean;
|
|
98
|
+
}
|
|
99
|
+
interface SponsoredQuotaConfig {
|
|
100
|
+
prePayFreeOpsLimit?: number;
|
|
101
|
+
opsGrantedPerReceipt?: number;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 3-tier anti-griefing quota tracker for developer-sponsored cross-ecosystem sessions.
|
|
105
|
+
* - Tier 1: Unpaid new external wallet gets at most `prePayFreeOpsLimit` (default 3) sponsored ops (e.g. session delegate + trial).
|
|
106
|
+
* - Tier 2: Each verified `ForeignReceipt` unlocks `opsGrantedPerReceipt` (default 50) sponsored ops.
|
|
107
|
+
* - Tier 3: Once exhausted, rejects sponsored execution until a new receipt is registered.
|
|
108
|
+
*/
|
|
109
|
+
declare class SponsoredQuotaTracker {
|
|
110
|
+
private readonly prePayFreeOpsLimit;
|
|
111
|
+
private readonly opsGrantedPerReceipt;
|
|
112
|
+
private readonly globalCreditedReceipts;
|
|
113
|
+
private readonly stateByDid;
|
|
114
|
+
constructor(config?: SponsoredQuotaConfig);
|
|
115
|
+
private getOrCreate;
|
|
116
|
+
creditForeignReceipt(did: string, receipt: Pick<ForeignReceiptRecord, 'receiptId' | 'status'> & {
|
|
117
|
+
buyerDid?: string;
|
|
118
|
+
}): number;
|
|
119
|
+
consumeSponsoredOp(did: string, count?: number): {
|
|
120
|
+
remainingOps: number;
|
|
121
|
+
totalUsedOps: number;
|
|
122
|
+
};
|
|
123
|
+
getRemainingOps(did: string): number;
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
export { ForeignQuoteSpec, ForeignReceiptKey, ForeignReceiptRecord, ForeignReceiptRegistry, ForeignReceiptStatus, ForeignVaultSplitResult, SponsoredQuotaConfig, SponsoredQuotaTracker, computeForeignQuoteDigest, computeForeignReceiptId, formatForeignReceiptKey, isAssetUnlockedByReceipt, sha256Hex, splitForeignVaultPayment };
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
//#region src/foreign-receipt.ts
|
|
2
|
+
const BPS_DENOMINATOR = 10000n;
|
|
3
|
+
const utf8Encoder = new TextEncoder();
|
|
4
|
+
const SHA256_K = new Uint32Array([
|
|
5
|
+
1116352408,
|
|
6
|
+
1899447441,
|
|
7
|
+
3049323471,
|
|
8
|
+
3921009573,
|
|
9
|
+
961987163,
|
|
10
|
+
1508970993,
|
|
11
|
+
2453635748,
|
|
12
|
+
2870763221,
|
|
13
|
+
3624381080,
|
|
14
|
+
310598401,
|
|
15
|
+
607225278,
|
|
16
|
+
1426881987,
|
|
17
|
+
1925078388,
|
|
18
|
+
2162078206,
|
|
19
|
+
2614888103,
|
|
20
|
+
3248222580,
|
|
21
|
+
3835390401,
|
|
22
|
+
4022224774,
|
|
23
|
+
264347078,
|
|
24
|
+
604807628,
|
|
25
|
+
770255983,
|
|
26
|
+
1249150122,
|
|
27
|
+
1555081692,
|
|
28
|
+
1996064986,
|
|
29
|
+
2554220882,
|
|
30
|
+
2821834349,
|
|
31
|
+
2952996808,
|
|
32
|
+
3210313671,
|
|
33
|
+
3336571891,
|
|
34
|
+
3584528711,
|
|
35
|
+
113926993,
|
|
36
|
+
338241895,
|
|
37
|
+
666307205,
|
|
38
|
+
773529912,
|
|
39
|
+
1294757372,
|
|
40
|
+
1396182291,
|
|
41
|
+
1695183700,
|
|
42
|
+
1986661051,
|
|
43
|
+
2177026350,
|
|
44
|
+
2456956037,
|
|
45
|
+
2730485921,
|
|
46
|
+
2820302411,
|
|
47
|
+
3259730800,
|
|
48
|
+
3345764771,
|
|
49
|
+
3516065817,
|
|
50
|
+
3600352804,
|
|
51
|
+
4094571909,
|
|
52
|
+
275423344,
|
|
53
|
+
430227734,
|
|
54
|
+
506948616,
|
|
55
|
+
659060556,
|
|
56
|
+
883997877,
|
|
57
|
+
958139571,
|
|
58
|
+
1322822218,
|
|
59
|
+
1537002063,
|
|
60
|
+
1747873779,
|
|
61
|
+
1955562222,
|
|
62
|
+
2024104815,
|
|
63
|
+
2227730452,
|
|
64
|
+
2361852424,
|
|
65
|
+
2428436474,
|
|
66
|
+
2756734187,
|
|
67
|
+
3204031479,
|
|
68
|
+
3329325298
|
|
69
|
+
]);
|
|
70
|
+
function rotr(x, n) {
|
|
71
|
+
return x >>> n | x << 32 - n;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Pure-TS FIPS 180-4 SHA-256 implementation (uses `node:crypto` fast path when available).
|
|
75
|
+
*/
|
|
76
|
+
function sha256Hex(data) {
|
|
77
|
+
const nodeCrypto = typeof process !== "undefined" ? process.getBuiltinModule?.("node:crypto") : void 0;
|
|
78
|
+
if (nodeCrypto?.createHash) return `0x${nodeCrypto.createHash("sha256").update(data).digest("hex")}`;
|
|
79
|
+
let h0 = 1779033703;
|
|
80
|
+
let h1 = 3144134277;
|
|
81
|
+
let h2 = 1013904242;
|
|
82
|
+
let h3 = 2773480762;
|
|
83
|
+
let h4 = 1359893119;
|
|
84
|
+
let h5 = 2600822924;
|
|
85
|
+
let h6 = 528734635;
|
|
86
|
+
let h7 = 1541459225;
|
|
87
|
+
const bitLenHi = Math.floor(data.byteLength / 536870912);
|
|
88
|
+
const bitLenLo = data.byteLength << 3 >>> 0;
|
|
89
|
+
const paddedLen = data.byteLength + 9 + 63 & -64;
|
|
90
|
+
const padded = new Uint8Array(paddedLen);
|
|
91
|
+
padded.set(data);
|
|
92
|
+
padded[data.byteLength] = 128;
|
|
93
|
+
const view = new DataView(padded.buffer);
|
|
94
|
+
view.setUint32(paddedLen - 8, bitLenHi, false);
|
|
95
|
+
view.setUint32(paddedLen - 4, bitLenLo, false);
|
|
96
|
+
const w = new Uint32Array(64);
|
|
97
|
+
for (let offset = 0; offset < paddedLen; offset += 64) {
|
|
98
|
+
for (let i = 0; i < 16; i++) w[i] = view.getUint32(offset + i * 4, false);
|
|
99
|
+
for (let i = 16; i < 64; i++) {
|
|
100
|
+
const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ w[i - 15] >>> 3;
|
|
101
|
+
const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ w[i - 2] >>> 10;
|
|
102
|
+
w[i] = w[i - 16] + s0 + w[i - 7] + s1 >>> 0;
|
|
103
|
+
}
|
|
104
|
+
let a = h0;
|
|
105
|
+
let b = h1;
|
|
106
|
+
let c = h2;
|
|
107
|
+
let d = h3;
|
|
108
|
+
let e = h4;
|
|
109
|
+
let f = h5;
|
|
110
|
+
let g = h6;
|
|
111
|
+
let h = h7;
|
|
112
|
+
for (let i = 0; i < 64; i++) {
|
|
113
|
+
const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
114
|
+
const ch = e & f ^ ~e & g;
|
|
115
|
+
const temp1 = h + S1 + ch + SHA256_K[i] + w[i] >>> 0;
|
|
116
|
+
const temp2 = (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + (a & b ^ a & c ^ b & c) >>> 0;
|
|
117
|
+
h = g;
|
|
118
|
+
g = f;
|
|
119
|
+
f = e;
|
|
120
|
+
e = d + temp1 >>> 0;
|
|
121
|
+
d = c;
|
|
122
|
+
c = b;
|
|
123
|
+
b = a;
|
|
124
|
+
a = temp1 + temp2 >>> 0;
|
|
125
|
+
}
|
|
126
|
+
h0 = h0 + a >>> 0;
|
|
127
|
+
h1 = h1 + b >>> 0;
|
|
128
|
+
h2 = h2 + c >>> 0;
|
|
129
|
+
h3 = h3 + d >>> 0;
|
|
130
|
+
h4 = h4 + e >>> 0;
|
|
131
|
+
h5 = h5 + f >>> 0;
|
|
132
|
+
h6 = h6 + g >>> 0;
|
|
133
|
+
h7 = h7 + h >>> 0;
|
|
134
|
+
}
|
|
135
|
+
return `0x${[
|
|
136
|
+
h0,
|
|
137
|
+
h1,
|
|
138
|
+
h2,
|
|
139
|
+
h3,
|
|
140
|
+
h4,
|
|
141
|
+
h5,
|
|
142
|
+
h6,
|
|
143
|
+
h7
|
|
144
|
+
].map((v) => (v >>> 0).toString(16).padStart(8, "0")).join("")}`;
|
|
145
|
+
}
|
|
146
|
+
function parsePositiveBigInt(value, label) {
|
|
147
|
+
let bn;
|
|
148
|
+
try {
|
|
149
|
+
bn = typeof value === "bigint" ? value : BigInt(String(value).trim());
|
|
150
|
+
} catch {
|
|
151
|
+
throw new Error(`Invalid ${label}: must be an integer`);
|
|
152
|
+
}
|
|
153
|
+
if (bn <= 0n) throw new Error(`Invalid ${label}: must be strictly positive`);
|
|
154
|
+
return bn;
|
|
155
|
+
}
|
|
156
|
+
function assertNonEmptyTrimmed(value, label) {
|
|
157
|
+
if (typeof value !== "string" || !value.trim()) throw new Error(`Invalid ${label}: must be a non-empty string`);
|
|
158
|
+
return value.trim();
|
|
159
|
+
}
|
|
160
|
+
function assertBpsRange(bps, label) {
|
|
161
|
+
if (!Number.isInteger(bps) || bps < 0 || bps > 1e4) throw new Error(`Invalid ${label}: must be an integer in [0, 10000]`);
|
|
162
|
+
}
|
|
163
|
+
function normalizeVaultOrTokenAddress(addr) {
|
|
164
|
+
return /^0x[0-9a-fA-F]+$/.test(addr) ? addr.toLowerCase() : addr;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Validate a `ForeignQuoteSpec` and compute its deterministic canonical SHA-256 digest (`0x...`).
|
|
168
|
+
*/
|
|
169
|
+
function computeForeignQuoteDigest(quote, nowMs) {
|
|
170
|
+
const quoteId = assertNonEmptyTrimmed(quote.quoteId, "quoteId");
|
|
171
|
+
const sourceChainId = assertNonEmptyTrimmed(quote.sourceChainId, "sourceChainId").toLowerCase();
|
|
172
|
+
const vaultAddress = assertNonEmptyTrimmed(quote.vaultAddress, "vaultAddress");
|
|
173
|
+
const paymentToken = assertNonEmptyTrimmed(quote.paymentToken, "paymentToken");
|
|
174
|
+
const paymentAmount = parsePositiveBigInt(quote.paymentAmount, "paymentAmount").toString(10);
|
|
175
|
+
const targetChainId = assertNonEmptyTrimmed(quote.targetChainId, "targetChainId");
|
|
176
|
+
const targetFactoryAddress = assertNonEmptyTrimmed(quote.targetFactoryAddress, "targetFactoryAddress");
|
|
177
|
+
const buyerDid = assertNonEmptyTrimmed(quote.buyerDid, "buyerDid");
|
|
178
|
+
assertBpsRange(quote.maxSlippageBps, "maxSlippageBps");
|
|
179
|
+
assertBpsRange(quote.reserveBps, "reserveBps");
|
|
180
|
+
if (!Number.isSafeInteger(quote.expiresAt) || quote.expiresAt <= 0) throw new Error("Invalid expiresAt: must be a positive safe integer timestamp");
|
|
181
|
+
if (nowMs !== void 0) {
|
|
182
|
+
if (!Number.isSafeInteger(nowMs) || nowMs < 0) throw new Error("Invalid nowMs: must be a non-negative safe integer timestamp");
|
|
183
|
+
if (quote.expiresAt <= nowMs) throw new Error("Foreign quote has expired");
|
|
184
|
+
}
|
|
185
|
+
const canonicalPayload = {
|
|
186
|
+
version: 1,
|
|
187
|
+
quoteId,
|
|
188
|
+
sourceChainId,
|
|
189
|
+
vaultAddress: normalizeVaultOrTokenAddress(vaultAddress),
|
|
190
|
+
paymentToken: normalizeVaultOrTokenAddress(paymentToken),
|
|
191
|
+
paymentAmount,
|
|
192
|
+
targetChainId,
|
|
193
|
+
targetFactoryAddress,
|
|
194
|
+
buyerDid,
|
|
195
|
+
maxSlippageBps: quote.maxSlippageBps,
|
|
196
|
+
reserveBps: quote.reserveBps,
|
|
197
|
+
expiresAt: quote.expiresAt
|
|
198
|
+
};
|
|
199
|
+
return sha256Hex(utf8Encoder.encode(JSON.stringify(canonicalPayload)));
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Build the canonical 4-tuple idempotency key string `(sourceChainId, vaultAddress, txHash, eventIndex)`.
|
|
203
|
+
*/
|
|
204
|
+
function formatForeignReceiptKey(key) {
|
|
205
|
+
const sourceChainId = assertNonEmptyTrimmed(key.sourceChainId, "sourceChainId").toLowerCase();
|
|
206
|
+
const vaultAddress = normalizeVaultOrTokenAddress(assertNonEmptyTrimmed(key.vaultAddress, "vaultAddress"));
|
|
207
|
+
const rawTx = assertNonEmptyTrimmed(key.txHash, "txHash");
|
|
208
|
+
const txHash = /^0x[0-9a-fA-F]+$/.test(rawTx) ? rawTx.toLowerCase() : rawTx;
|
|
209
|
+
if (vaultAddress.includes(":") || txHash.includes(":")) throw new Error("Invalid ForeignReceiptKey: vaultAddress and txHash cannot contain \":\" delimiter");
|
|
210
|
+
if (!Number.isSafeInteger(key.eventIndex) || key.eventIndex < 0) throw new Error("Invalid eventIndex: must be a non-negative safe integer");
|
|
211
|
+
return `${sourceChainId}:${vaultAddress}:${txHash}:${key.eventIndex}`;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Compute a deterministic receipt ID (`0x...`) from the 4-tuple idempotency key.
|
|
215
|
+
*/
|
|
216
|
+
function computeForeignReceiptId(key) {
|
|
217
|
+
const formatted = formatForeignReceiptKey(key);
|
|
218
|
+
return sha256Hex(utf8Encoder.encode(`arcblock:foreign-receipt:v1:${formatted}`));
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Deterministically split an external payment into `reserveBucket` (locked for floor/payout redemptions),
|
|
222
|
+
* `protocolFeeBucket`, and `devBucket` (studio revenue).
|
|
223
|
+
* Guarantees exact conservation: `reserveBucket + protocolFeeBucket + devBucket === totalAmount`.
|
|
224
|
+
*/
|
|
225
|
+
function splitForeignVaultPayment(paymentAmount, reserveBps, protocolFeeBps = 0) {
|
|
226
|
+
const totalAmount = parsePositiveBigInt(paymentAmount, "paymentAmount");
|
|
227
|
+
assertBpsRange(reserveBps, "reserveBps");
|
|
228
|
+
assertBpsRange(protocolFeeBps, "protocolFeeBps");
|
|
229
|
+
if (reserveBps + protocolFeeBps > 1e4) throw new Error("Invalid split: reserveBps + protocolFeeBps cannot exceed 10000");
|
|
230
|
+
const reserveBucket = totalAmount * BigInt(reserveBps) / BPS_DENOMINATOR;
|
|
231
|
+
const protocolFeeBucket = totalAmount * BigInt(protocolFeeBps) / BPS_DENOMINATOR;
|
|
232
|
+
return {
|
|
233
|
+
totalAmount,
|
|
234
|
+
reserveBucket,
|
|
235
|
+
protocolFeeBucket,
|
|
236
|
+
devBucket: totalAmount - reserveBucket - protocolFeeBucket,
|
|
237
|
+
reserveBps,
|
|
238
|
+
protocolFeeBps
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Check whether an asset minted via a `ForeignReceiptRecord` is unlocked for secondary transfer,
|
|
243
|
+
* floor burn redemption, or external payout.
|
|
244
|
+
* Assets minted under `PROVISIONAL` confirmation are locked until promoted to `FINAL`.
|
|
245
|
+
*/
|
|
246
|
+
function isAssetUnlockedByReceipt(record) {
|
|
247
|
+
return record.status === "FINAL";
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* In-memory deterministic registry for `ForeignReceipt` idempotency and two-stage (`PROVISIONAL -> FINAL`) finality.
|
|
251
|
+
*/
|
|
252
|
+
var ForeignReceiptRegistry = class {
|
|
253
|
+
constructor() {
|
|
254
|
+
this.byReceiptId = /* @__PURE__ */ new Map();
|
|
255
|
+
this.byIdempotencyKey = /* @__PURE__ */ new Map();
|
|
256
|
+
this.byQuoteId = /* @__PURE__ */ new Map();
|
|
257
|
+
}
|
|
258
|
+
registerReceipt(params) {
|
|
259
|
+
const idempotencyKey = formatForeignReceiptKey(params.key);
|
|
260
|
+
if (this.byIdempotencyKey.has(idempotencyKey)) throw new Error(`Duplicate foreign receipt key: ${idempotencyKey}`);
|
|
261
|
+
const quoteDigest = computeForeignQuoteDigest(params.quote, params.nowMs);
|
|
262
|
+
const normalizedQuoteId = assertNonEmptyTrimmed(params.quote.quoteId, "quoteId");
|
|
263
|
+
if (this.byQuoteId.has(normalizedQuoteId)) throw new Error(`Duplicate quoteId consumption: ${normalizedQuoteId}`);
|
|
264
|
+
const keyChainId = params.key.sourceChainId.trim().toLowerCase();
|
|
265
|
+
const quoteChainId = params.quote.sourceChainId.trim().toLowerCase();
|
|
266
|
+
if (keyChainId !== quoteChainId) throw new Error(`Receipt sourceChainId (${keyChainId}) does not match quote sourceChainId (${quoteChainId})`);
|
|
267
|
+
const keyVault = normalizeVaultOrTokenAddress(params.key.vaultAddress.trim());
|
|
268
|
+
const quoteVault = normalizeVaultOrTokenAddress(params.quote.vaultAddress.trim());
|
|
269
|
+
if (keyVault !== quoteVault) throw new Error(`Receipt vaultAddress (${keyVault}) does not match quote vaultAddress (${quoteVault})`);
|
|
270
|
+
if (params.sourceBlockNumber !== void 0 && (!Number.isSafeInteger(params.sourceBlockNumber) || params.sourceBlockNumber < 0)) throw new Error("Invalid sourceBlockNumber: must be a non-negative safe integer");
|
|
271
|
+
const receiptId = computeForeignReceiptId(params.key);
|
|
272
|
+
const split = splitForeignVaultPayment(params.quote.paymentAmount, params.quote.reserveBps, params.protocolFeeBps ?? 0);
|
|
273
|
+
const status = params.status ?? "PROVISIONAL";
|
|
274
|
+
const record = {
|
|
275
|
+
receiptId,
|
|
276
|
+
idempotencyKey,
|
|
277
|
+
quoteId: normalizedQuoteId,
|
|
278
|
+
quoteDigest,
|
|
279
|
+
sourceChainId: keyChainId,
|
|
280
|
+
vaultAddress: params.key.vaultAddress.trim(),
|
|
281
|
+
txHash: params.key.txHash.trim(),
|
|
282
|
+
eventIndex: params.key.eventIndex,
|
|
283
|
+
buyerDid: params.quote.buyerDid.trim(),
|
|
284
|
+
targetFactoryAddress: params.quote.targetFactoryAddress.trim(),
|
|
285
|
+
paymentToken: params.quote.paymentToken.trim(),
|
|
286
|
+
paymentAmount: split.totalAmount.toString(10),
|
|
287
|
+
reserveBucket: split.reserveBucket.toString(10),
|
|
288
|
+
protocolFeeBucket: split.protocolFeeBucket.toString(10),
|
|
289
|
+
devBucket: split.devBucket.toString(10),
|
|
290
|
+
status,
|
|
291
|
+
sourceBlockNumber: params.sourceBlockNumber,
|
|
292
|
+
finalizedBlockNumber: status === "FINAL" ? params.sourceBlockNumber : void 0
|
|
293
|
+
};
|
|
294
|
+
this.byReceiptId.set(receiptId, record);
|
|
295
|
+
this.byIdempotencyKey.set(idempotencyKey, receiptId);
|
|
296
|
+
this.byQuoteId.set(normalizedQuoteId, receiptId);
|
|
297
|
+
return { ...record };
|
|
298
|
+
}
|
|
299
|
+
promoteToFinal(receiptId, finalizedBlockNumber) {
|
|
300
|
+
const existing = this.byReceiptId.get(receiptId);
|
|
301
|
+
if (!existing) throw new Error(`Unknown foreign receiptId: ${receiptId}`);
|
|
302
|
+
if (existing.status === "REORG_CANCELLED") throw new Error(`Cannot promote reorg-cancelled receipt: ${receiptId}`);
|
|
303
|
+
if (finalizedBlockNumber !== void 0) {
|
|
304
|
+
if (!Number.isSafeInteger(finalizedBlockNumber) || finalizedBlockNumber < 0) throw new Error("Invalid finalizedBlockNumber: must be a non-negative safe integer");
|
|
305
|
+
if (existing.sourceBlockNumber !== void 0 && finalizedBlockNumber < existing.sourceBlockNumber) throw new Error("finalizedBlockNumber cannot be less than sourceBlockNumber");
|
|
306
|
+
if (existing.status === "FINAL" && existing.finalizedBlockNumber !== void 0 && existing.finalizedBlockNumber !== finalizedBlockNumber) throw new Error(`Receipt ${receiptId} is already finalized at block ${existing.finalizedBlockNumber}`);
|
|
307
|
+
existing.finalizedBlockNumber = finalizedBlockNumber;
|
|
308
|
+
}
|
|
309
|
+
existing.status = "FINAL";
|
|
310
|
+
return { ...existing };
|
|
311
|
+
}
|
|
312
|
+
markReorgCancelled(receiptId, reason) {
|
|
313
|
+
const existing = this.byReceiptId.get(receiptId);
|
|
314
|
+
if (!existing) throw new Error(`Unknown foreign receiptId: ${receiptId}`);
|
|
315
|
+
if (existing.status === "FINAL") throw new Error(`Cannot cancel already finalized receipt: ${receiptId}`);
|
|
316
|
+
existing.status = "REORG_CANCELLED";
|
|
317
|
+
existing.reorgReason = reason;
|
|
318
|
+
return { ...existing };
|
|
319
|
+
}
|
|
320
|
+
getByReceiptId(receiptId) {
|
|
321
|
+
const rec = this.byReceiptId.get(receiptId);
|
|
322
|
+
return rec ? { ...rec } : void 0;
|
|
323
|
+
}
|
|
324
|
+
hasIdempotencyKey(key) {
|
|
325
|
+
return this.byIdempotencyKey.has(formatForeignReceiptKey(key));
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
/**
|
|
329
|
+
* 3-tier anti-griefing quota tracker for developer-sponsored cross-ecosystem sessions.
|
|
330
|
+
* - Tier 1: Unpaid new external wallet gets at most `prePayFreeOpsLimit` (default 3) sponsored ops (e.g. session delegate + trial).
|
|
331
|
+
* - Tier 2: Each verified `ForeignReceipt` unlocks `opsGrantedPerReceipt` (default 50) sponsored ops.
|
|
332
|
+
* - Tier 3: Once exhausted, rejects sponsored execution until a new receipt is registered.
|
|
333
|
+
*/
|
|
334
|
+
var SponsoredQuotaTracker = class {
|
|
335
|
+
constructor(config = {}) {
|
|
336
|
+
this.globalCreditedReceipts = /* @__PURE__ */ new Map();
|
|
337
|
+
this.stateByDid = /* @__PURE__ */ new Map();
|
|
338
|
+
this.prePayFreeOpsLimit = config.prePayFreeOpsLimit ?? 3;
|
|
339
|
+
this.opsGrantedPerReceipt = config.opsGrantedPerReceipt ?? 50;
|
|
340
|
+
}
|
|
341
|
+
getOrCreate(did) {
|
|
342
|
+
const key = assertNonEmptyTrimmed(did, "did");
|
|
343
|
+
let entry = this.stateByDid.get(key);
|
|
344
|
+
if (!entry) {
|
|
345
|
+
entry = {
|
|
346
|
+
usedOps: 0,
|
|
347
|
+
grantedOps: this.prePayFreeOpsLimit,
|
|
348
|
+
creditedReceipts: /* @__PURE__ */ new Set()
|
|
349
|
+
};
|
|
350
|
+
this.stateByDid.set(key, entry);
|
|
351
|
+
}
|
|
352
|
+
return entry;
|
|
353
|
+
}
|
|
354
|
+
creditForeignReceipt(did, receipt) {
|
|
355
|
+
if (receipt.status === "REORG_CANCELLED") throw new Error("Cannot credit sponsored quota for reorg-cancelled receipt");
|
|
356
|
+
if (receipt.status !== "PROVISIONAL" && receipt.status !== "FINAL") throw new Error("Invalid receipt status for sponsored quota credit");
|
|
357
|
+
const key = assertNonEmptyTrimmed(did, "did");
|
|
358
|
+
const receiptId = assertNonEmptyTrimmed(receipt.receiptId, "receiptId");
|
|
359
|
+
if (receipt.buyerDid !== void 0 && receipt.buyerDid.trim() !== key) throw new Error(`Receipt buyerDid (${receipt.buyerDid.trim()}) does not match credited DID (${key})`);
|
|
360
|
+
const existingOwner = this.globalCreditedReceipts.get(receiptId);
|
|
361
|
+
if (existingOwner !== void 0 && existingOwner !== key) throw new Error(`Foreign receipt ${receiptId} was already credited to another DID (${existingOwner})`);
|
|
362
|
+
const entry = this.getOrCreate(key);
|
|
363
|
+
if (entry.creditedReceipts.has(receiptId)) return entry.grantedOps - entry.usedOps;
|
|
364
|
+
this.globalCreditedReceipts.set(receiptId, key);
|
|
365
|
+
entry.creditedReceipts.add(receiptId);
|
|
366
|
+
entry.grantedOps += this.opsGrantedPerReceipt;
|
|
367
|
+
return entry.grantedOps - entry.usedOps;
|
|
368
|
+
}
|
|
369
|
+
consumeSponsoredOp(did, count = 1) {
|
|
370
|
+
if (!Number.isInteger(count) || count <= 0) throw new Error("Invalid op count: must be a positive integer");
|
|
371
|
+
const entry = this.getOrCreate(did);
|
|
372
|
+
if (entry.usedOps + count > entry.grantedOps) throw new Error(`Sponsored op quota exhausted for ${did} (${entry.usedOps}/${entry.grantedOps})`);
|
|
373
|
+
entry.usedOps += count;
|
|
374
|
+
return {
|
|
375
|
+
remainingOps: entry.grantedOps - entry.usedOps,
|
|
376
|
+
totalUsedOps: entry.usedOps
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
getRemainingOps(did) {
|
|
380
|
+
const key = assertNonEmptyTrimmed(did, "did");
|
|
381
|
+
const entry = this.stateByDid.get(key);
|
|
382
|
+
if (!entry) return this.prePayFreeOpsLimit;
|
|
383
|
+
return entry.grantedOps - entry.usedOps;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
//#endregion
|
|
388
|
+
export { ForeignReceiptRegistry, SponsoredQuotaTracker, computeForeignQuoteDigest, computeForeignReceiptId, formatForeignReceiptKey, isAssetUnlockedByReceipt, sha256Hex, splitForeignVaultPayment };
|
package/esm/index.d.mts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { BN } from "./bn.mjs";
|
|
2
2
|
import { scopeMatch, scopeMatchAny } from "./scope-match.mjs";
|
|
3
|
+
import { ArcadeFourWaySplitConfig, ArcadeMachineBankroll, ArcadePlaySettlementResult, ArcadeRtpMetrics, LootTableResolution, LootTableTier, PityConfig, ProvablyFairRollInput, ProvablyFairRollResult, RevenueSharePool, ShareHolderPosition, SplitGraphNodes, SplitRecipientEdge, assertMachineBankrollSolvency, deriveProvablyFairRoll, generateHashChain, resolveHierarchicalSplitDag, resolveWeightedLootTable, settleArcadeMachinePlay, verifyHashChainStep } from "./arcade.mjs";
|
|
4
|
+
import { AssetViewDescriptor, AssetViewFormat, AupMultiViewAssetManifest, BondingCurveMintConfig, BondingMintQuote, BondingReserveVault, GenerativeLayerOption, GenerativeTraitLayerSpec, ReserveBackedAssetRecord, buildAupMultiViewManifest, quoteBondingCurveMint } from "./bonding-reserve-aup.mjs";
|
|
5
|
+
import { ComposableAssetNode, ContainerSlotDefinition, LeaseMountTerms, MountedSlotAssignment, SlotMountMode, SynthesisExecutionResult, SynthesisRecipe, SynthesisRecipeRequirement, assertAssetRedeemableOrTransferable, assertNoContainerCycle, createComposableAssetNode, mountContainerSlotItem, synthesizeContainerRecipe, unmountContainerSlotItem } from "./composable-container.mjs";
|
|
6
|
+
import { ConditionalMarketConfig, ConditionalMarketFeeConfig, ConditionalMarketPool, ConditionalMarketStatus, ConditionalResolutionChallenge, ConditionalResolutionProposal, FinalizeResolutionResult, OutcomeBuyQuote } from "./conditional-market.mjs";
|
|
7
|
+
import { ForeignQuoteSpec, ForeignReceiptKey, ForeignReceiptRecord, ForeignReceiptRegistry, ForeignReceiptStatus, ForeignVaultSplitResult, SponsoredQuotaConfig, SponsoredQuotaTracker, computeForeignQuoteDigest, computeForeignReceiptId, formatForeignReceiptKey, isAssetUnlockedByReceipt, sha256Hex, splitForeignVaultPayment } from "./foreign-receipt.mjs";
|
|
8
|
+
import { Direction, calcConstantCost, calcConstantPrice, calcCost, calcFee, calcLinearCost, calcLinearPrice, calcPrice, calcQuadraticCost, calcQuadraticPrice, calcQuotaMintFromPayment, consumePrepaidQuota } from "./curve.mjs";
|
|
9
|
+
import { BNInput, MAX_TOTAL_FEE_BPS, MINIMUM_LIQUIDITY, calcAddLiquidity, calcGraduationSettlement, calcGraduationSupplySplit, calcInitialLiquidity, calcLimitOrderFill, calcRemoveLiquidity, calcSwapExactIn, calcSwapExactOut, isqrt } from "./amm.mjs";
|
|
3
10
|
import { LiteralUnion } from "type-fest";
|
|
4
11
|
|
|
5
12
|
//#region src/index.d.ts
|
|
@@ -228,4 +235,4 @@ declare function isSameDid(a: string, b: string): boolean;
|
|
|
228
235
|
declare function extractMethod(did: unknown): string | null;
|
|
229
236
|
declare function formatTxType(type: string): string;
|
|
230
237
|
//#endregion
|
|
231
|
-
export { BN, BytesType, EncodingType, KeyPairType, UUID, bytesToHex, extractMethod, formatTxType, fromBase58, fromBase64, fromTokenToUnit, fromUnitToToken, hexToBytes, hexToNumber, hexToUtf8, isBN, isBase58btc, isBigNumber, isHex, isHexPrefixed, isHexStrict, isSameDid, isUUID, isUint8Array, leftPad, numberToBN, numberToHex, numberToString, rightPad, scopeMatch, scopeMatchAny, stripHexPrefix, toAddress, toBN, toBase58, toBase64, toBuffer, toDid, toHex, toUint8Array, utf8ToHex };
|
|
238
|
+
export { ArcadeFourWaySplitConfig, ArcadeMachineBankroll, ArcadePlaySettlementResult, ArcadeRtpMetrics, AssetViewDescriptor, AssetViewFormat, AupMultiViewAssetManifest, BN, BNInput, BondingCurveMintConfig, BondingMintQuote, BondingReserveVault, BytesType, ComposableAssetNode, ConditionalMarketConfig, ConditionalMarketFeeConfig, ConditionalMarketPool, ConditionalMarketStatus, ConditionalResolutionChallenge, ConditionalResolutionProposal, ContainerSlotDefinition, Direction, EncodingType, FinalizeResolutionResult, ForeignQuoteSpec, ForeignReceiptKey, ForeignReceiptRecord, ForeignReceiptRegistry, ForeignReceiptStatus, ForeignVaultSplitResult, GenerativeLayerOption, GenerativeTraitLayerSpec, KeyPairType, LeaseMountTerms, LootTableResolution, LootTableTier, MAX_TOTAL_FEE_BPS, MINIMUM_LIQUIDITY, MountedSlotAssignment, OutcomeBuyQuote, PityConfig, ProvablyFairRollInput, ProvablyFairRollResult, ReserveBackedAssetRecord, RevenueSharePool, ShareHolderPosition, SlotMountMode, SplitGraphNodes, SplitRecipientEdge, SponsoredQuotaConfig, SponsoredQuotaTracker, SynthesisExecutionResult, SynthesisRecipe, SynthesisRecipeRequirement, UUID, assertAssetRedeemableOrTransferable, assertMachineBankrollSolvency, assertNoContainerCycle, buildAupMultiViewManifest, bytesToHex, calcAddLiquidity, calcConstantCost, calcConstantPrice, calcCost, calcFee, calcGraduationSettlement, calcGraduationSupplySplit, calcInitialLiquidity, calcLimitOrderFill, calcLinearCost, calcLinearPrice, calcPrice, calcQuadraticCost, calcQuadraticPrice, calcQuotaMintFromPayment, calcRemoveLiquidity, calcSwapExactIn, calcSwapExactOut, computeForeignQuoteDigest, computeForeignReceiptId, consumePrepaidQuota, createComposableAssetNode, deriveProvablyFairRoll, extractMethod, formatForeignReceiptKey, formatTxType, fromBase58, fromBase64, fromTokenToUnit, fromUnitToToken, generateHashChain, hexToBytes, hexToNumber, hexToUtf8, isAssetUnlockedByReceipt, isBN, isBase58btc, isBigNumber, isHex, isHexPrefixed, isHexStrict, isSameDid, isUUID, isUint8Array, isqrt, leftPad, mountContainerSlotItem, numberToBN, numberToHex, numberToString, quoteBondingCurveMint, resolveHierarchicalSplitDag, resolveWeightedLootTable, rightPad, scopeMatch, scopeMatchAny, settleArcadeMachinePlay, sha256Hex, splitForeignVaultPayment, stripHexPrefix, synthesizeContainerRecipe, toAddress, toBN, toBase58, toBase64, toBuffer, toDid, toHex, toUint8Array, unmountContainerSlotItem, utf8ToHex, verifyHashChainStep };
|