@anywalletkit/protocol-swap2-omniston 0.2.7 → 0.3.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/README.md +18 -1
- package/dist/{chunk-IIFNHGC5.js → chunk-CRYYP6X3.js} +2 -2
- package/dist/{chunk-PKDRSR7N.js → chunk-JVFDD7PV.js} +116 -9
- package/dist/chunk-JVFDD7PV.js.map +1 -0
- package/dist/index.cjs +116 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +10 -4
- package/dist/protocol.cjs +52 -8
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +1 -1
- package/dist/protocol.d.ts +1 -1
- package/dist/protocol.js +2 -2
- package/dist/provider.cjs +116 -9
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.cts +64 -2
- package/dist/provider.d.ts +64 -2
- package/dist/provider.js +9 -3
- package/dist/validators.cjs.map +1 -1
- package/dist/validators.d.cts +1 -1
- package/dist/validators.d.ts +1 -1
- package/dist/validators.js.map +1 -1
- package/package.json +16 -8
- package/dist/chunk-PKDRSR7N.js.map +0 -1
- /package/dist/{chunk-IIFNHGC5.js.map → chunk-CRYYP6X3.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { omniston } from './config.cjs';
|
|
2
|
-
export { HtlcSecretStore, OmnistonClientLike, OmnistonProviderOptions, OmnistonQuoteStore, TON_SWAP_PROTOCOL_LAYOUTS, TonSwapCheckInput, TonSwapCheckResult, TonSwapLeg, TonSwapPayloadError, checkTonSwapPayload, encodeTypedMessage, inMemoryQuoteStore, inMemorySecretStore, omnistonProvider, validateEvmToTonOrderExtension } from './provider.cjs';
|
|
3
|
-
export { OmnistonSwap2Protocol, OmnistonSwap2Protocol as default } from './protocol.cjs';
|
|
2
|
+
export { AssetId, ChainAddress, EscrowMessage, HtlcSecretStore, ObservableLike, OmnistonClientLike, OmnistonProviderOptions, OmnistonQuote, OmnistonQuoteStore, OrderEvent, OrderExecution, OrderSettlement, OrderSnapshot, QuoteRequest, RfqEvent, SwapSettlement, SwapTrackEvent, TON_SWAP_PROTOCOL_LAYOUTS, TonSwapCheckInput, TonSwapCheckResult, TonSwapLeg, TonSwapPayloadError, checkTonSwapPayload, encodeTypedMessage, inMemoryQuoteStore, inMemorySecretStore, omnistonPins, omnistonProvider, omnistonVerifyBuild, validateEvmToTonOrderExtension, validateEvmTypedOrder } from './provider.cjs';
|
|
3
|
+
export { OmnistonSwap2Config, OmnistonSwap2Protocol, OmnistonSwap2Protocol as default } from './protocol.cjs';
|
|
4
4
|
export { OMNISTON_ESCROWS, OMNISTON_MODULE, STONFI_ROUTERS, describeOmnistonActivity } from './activity.cjs';
|
|
5
5
|
import '@anywalletkit/protocol-swap2-core/types';
|
|
6
6
|
import '@anywalletkit/protocol-swap2-core/swap2/single';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { omniston } from './config.js';
|
|
2
|
-
export { HtlcSecretStore, OmnistonClientLike, OmnistonProviderOptions, OmnistonQuoteStore, TON_SWAP_PROTOCOL_LAYOUTS, TonSwapCheckInput, TonSwapCheckResult, TonSwapLeg, TonSwapPayloadError, checkTonSwapPayload, encodeTypedMessage, inMemoryQuoteStore, inMemorySecretStore, omnistonProvider, validateEvmToTonOrderExtension } from './provider.js';
|
|
3
|
-
export { OmnistonSwap2Protocol, OmnistonSwap2Protocol as default } from './protocol.js';
|
|
2
|
+
export { AssetId, ChainAddress, EscrowMessage, HtlcSecretStore, ObservableLike, OmnistonClientLike, OmnistonProviderOptions, OmnistonQuote, OmnistonQuoteStore, OrderEvent, OrderExecution, OrderSettlement, OrderSnapshot, QuoteRequest, RfqEvent, SwapSettlement, SwapTrackEvent, TON_SWAP_PROTOCOL_LAYOUTS, TonSwapCheckInput, TonSwapCheckResult, TonSwapLeg, TonSwapPayloadError, checkTonSwapPayload, encodeTypedMessage, inMemoryQuoteStore, inMemorySecretStore, omnistonPins, omnistonProvider, omnistonVerifyBuild, validateEvmToTonOrderExtension, validateEvmTypedOrder } from './provider.js';
|
|
3
|
+
export { OmnistonSwap2Config, OmnistonSwap2Protocol, OmnistonSwap2Protocol as default } from './protocol.js';
|
|
4
4
|
export { OMNISTON_ESCROWS, OMNISTON_MODULE, STONFI_ROUTERS, describeOmnistonActivity } from './activity.js';
|
|
5
5
|
import '@anywalletkit/protocol-swap2-core/types';
|
|
6
6
|
import '@anywalletkit/protocol-swap2-core/swap2/single';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OmnistonSwap2Protocol
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-CRYYP6X3.js";
|
|
4
4
|
import {
|
|
5
5
|
TON_SWAP_PROTOCOL_LAYOUTS,
|
|
6
6
|
TonSwapPayloadError,
|
|
@@ -8,9 +8,12 @@ import {
|
|
|
8
8
|
encodeTypedMessage,
|
|
9
9
|
inMemoryQuoteStore,
|
|
10
10
|
inMemorySecretStore,
|
|
11
|
+
omnistonPins,
|
|
11
12
|
omnistonProvider,
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
omnistonVerifyBuild,
|
|
14
|
+
validateEvmToTonOrderExtension,
|
|
15
|
+
validateEvmTypedOrder
|
|
16
|
+
} from "./chunk-JVFDD7PV.js";
|
|
14
17
|
import {
|
|
15
18
|
omniston
|
|
16
19
|
} from "./chunk-QDXFC6BC.js";
|
|
@@ -34,7 +37,10 @@ export {
|
|
|
34
37
|
inMemoryQuoteStore,
|
|
35
38
|
inMemorySecretStore,
|
|
36
39
|
omniston,
|
|
40
|
+
omnistonPins,
|
|
37
41
|
omnistonProvider,
|
|
38
|
-
|
|
42
|
+
omnistonVerifyBuild,
|
|
43
|
+
validateEvmToTonOrderExtension,
|
|
44
|
+
validateEvmTypedOrder
|
|
39
45
|
};
|
|
40
46
|
//# sourceMappingURL=index.js.map
|
package/dist/protocol.cjs
CHANGED
|
@@ -452,7 +452,12 @@ function inMemoryQuoteStore() {
|
|
|
452
452
|
return {
|
|
453
453
|
save: (id, v) => void map.set(id, v),
|
|
454
454
|
load: (id) => map.get(id),
|
|
455
|
-
clear: (id) => void map.delete(id)
|
|
455
|
+
clear: (id) => void map.delete(id),
|
|
456
|
+
claim: (id, v) => {
|
|
457
|
+
if (map.has(id)) return false;
|
|
458
|
+
map.set(id, v);
|
|
459
|
+
return true;
|
|
460
|
+
}
|
|
456
461
|
};
|
|
457
462
|
}
|
|
458
463
|
function inMemorySecretStore() {
|
|
@@ -1026,6 +1031,13 @@ function validSwapSettlement(q) {
|
|
|
1026
1031
|
const v = q.settlementData.value;
|
|
1027
1032
|
return Array.isArray(v.routes) && v.routes.length > 0 && v.routes.every((route) => Array.isArray(route?.steps) && route.steps.length > 0 && route.steps.every((step) => Array.isArray(step?.chunks) && step.chunks.length > 0 && step.chunks.every((chunk) => typeof chunk?.protocol === "string" && chunk.protocol.length > 0 && isPositiveInteger(chunk.inputUnits) && isPositiveInteger(chunk.outputUnits)))) && isPositiveInteger(v.minOutputAmount) && BigInt(v.minOutputAmount) <= BigInt(q.outputUnits) && (v.recommendedMinOutputAmount === void 0 || isPositiveInteger(v.recommendedMinOutputAmount) && BigInt(v.recommendedMinOutputAmount) <= BigInt(q.outputUnits)) && (q.gasBudget === void 0 || isPositiveInteger(q.gasBudget));
|
|
1028
1033
|
}
|
|
1034
|
+
function swapSteps(v) {
|
|
1035
|
+
if (v.routes.length !== 1) return [{ protocol: `${v.routes.length}-routes`, inputJetton: void 0, outputJetton: void 0 }];
|
|
1036
|
+
return v.routes[0].steps.map((step) => {
|
|
1037
|
+
if (step.chunks.length !== 1) return { protocol: `split(${step.chunks.map((c) => c.protocol).join("|")})`, inputJetton: void 0, outputJetton: void 0 };
|
|
1038
|
+
return { protocol: step.chunks[0].protocol, inputJetton: stepJetton(step.inputAsset), outputJetton: stepJetton(step.outputAsset) };
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1029
1041
|
function swapProtocols(v) {
|
|
1030
1042
|
const names = /* @__PURE__ */ new Set();
|
|
1031
1043
|
for (const route of v.routes) for (const step of route.steps) for (const chunk of step.chunks) names.add(chunk.protocol);
|
|
@@ -1319,6 +1331,26 @@ function omnistonProvider(opts = {}) {
|
|
|
1319
1331
|
async function saveBuilt(quoteId, entry) {
|
|
1320
1332
|
await quotes.save(quoteId, JSON.stringify(entry));
|
|
1321
1333
|
}
|
|
1334
|
+
async function claimBuilt(quoteId, entry) {
|
|
1335
|
+
const json = JSON.stringify(entry);
|
|
1336
|
+
if (typeof quotes.claim === "function") {
|
|
1337
|
+
if (await quotes.claim(quoteId, json)) return true;
|
|
1338
|
+
} else if (!await quotes.load(quoteId)) {
|
|
1339
|
+
await quotes.save(quoteId, json);
|
|
1340
|
+
return true;
|
|
1341
|
+
}
|
|
1342
|
+
const existing = await loadBuilt(quoteId);
|
|
1343
|
+
if (!existing) {
|
|
1344
|
+
if (typeof quotes.claim === "function") return await quotes.claim(quoteId, json);
|
|
1345
|
+
await quotes.save(quoteId, json);
|
|
1346
|
+
return true;
|
|
1347
|
+
}
|
|
1348
|
+
const a = existing.bound, b = entry.bound;
|
|
1349
|
+
const same = !!a && !!b && a.kind === b.kind && a.srcChain === b.srcChain && sameIntentAddress(a.trader, b.trader) && sameIntentAddress(a.dest, b.dest);
|
|
1350
|
+
if (!same) return false;
|
|
1351
|
+
await quotes.save(quoteId, json);
|
|
1352
|
+
return true;
|
|
1353
|
+
}
|
|
1322
1354
|
async function loadBuilt(quoteId) {
|
|
1323
1355
|
const raw2 = await quotes.load(quoteId);
|
|
1324
1356
|
if (!raw2) return void 0;
|
|
@@ -1485,7 +1517,10 @@ function omnistonProvider(opts = {}) {
|
|
|
1485
1517
|
if (BigInt(swap.minOutputAmount) < requiredMin(q.outputUnits)) return null;
|
|
1486
1518
|
if (q.gasBudget !== void 0 && BigInt(q.gasBudget) > BigInt(maxTonExecutionNano)) return null;
|
|
1487
1519
|
const minOut = swap.minOutputAmount;
|
|
1488
|
-
await
|
|
1520
|
+
if (!await claimBuilt(q.quoteId, { quote: q, at: Date.now(), bound: { trader, dest: params.destAddress, srcChain: params.sourceChain, kind: "swap" } })) {
|
|
1521
|
+
traceFor(q.quoteId)("quote-id-reused", { kind: "swap" });
|
|
1522
|
+
return null;
|
|
1523
|
+
}
|
|
1489
1524
|
const feeUnits = Number(q.protocolFeeUnits || "0") + Number(q.integratorFeeUnits || "0");
|
|
1490
1525
|
const stableOut = /^(USDT|USDC|USD₮|jUSDT)$/.test(dest.symbol);
|
|
1491
1526
|
const feeUsd = stableOut ? feeUnits / 10 ** dest.decimals : 0;
|
|
@@ -1512,6 +1547,8 @@ function omnistonProvider(opts = {}) {
|
|
|
1512
1547
|
providerData: {
|
|
1513
1548
|
settlement: "swap",
|
|
1514
1549
|
protocols: swapProtocols(swap).join(","),
|
|
1550
|
+
// For the app's own check of a remote build (omnistonVerifyBuild): the route the body must follow.
|
|
1551
|
+
routeSteps: JSON.stringify(swapSteps(swap)),
|
|
1515
1552
|
...q.gasBudget ? { gasBudget: q.gasBudget } : {},
|
|
1516
1553
|
...q.estimatedGasConsumption ? { gasEstimate: q.estimatedGasConsumption } : {}
|
|
1517
1554
|
}
|
|
@@ -1612,10 +1649,7 @@ function omnistonProvider(opts = {}) {
|
|
|
1612
1649
|
minOutputAmount: swap.minOutputAmount,
|
|
1613
1650
|
inputJetton,
|
|
1614
1651
|
outputJetton: assetContract(q.outputAsset),
|
|
1615
|
-
steps: swap
|
|
1616
|
-
if (step.chunks.length !== 1) return { protocol: `split(${step.chunks.map((c) => c.protocol).join("|")})`, inputJetton: void 0, outputJetton: void 0 };
|
|
1617
|
-
return { protocol: step.chunks[0].protocol, inputJetton: stepJetton(step.inputAsset), outputJetton: stepJetton(step.outputAsset) };
|
|
1618
|
-
}) : [{ protocol: `${swap.routes.length}-routes`, inputJetton: void 0, outputJetton: void 0 }],
|
|
1652
|
+
steps: swapSteps(swap),
|
|
1619
1653
|
integratorAddress: q.integratorAddress?.chain.$case === "ton" ? q.integratorAddress.chain.value : null
|
|
1620
1654
|
});
|
|
1621
1655
|
} catch (error) {
|
|
@@ -1903,7 +1937,9 @@ function omnistonProvider(opts = {}) {
|
|
|
1903
1937
|
const outputScaled = BigInt(q.outputUnits) * 10n ** BigInt(source.decimals);
|
|
1904
1938
|
if (outputScaled * 2n < inputScaled || outputScaled > inputScaled * 2n) return refuse2("quoted output is outside 0.5x\u20132x of the input");
|
|
1905
1939
|
if (await quoteIdInUse(q.quoteId)) return refuse2("the platform reused a quote id that already belongs to an order");
|
|
1906
|
-
await
|
|
1940
|
+
if (!await claimBuilt(q.quoteId, { quote: q, at: Date.now(), bound: { trader, dest: params.destAddress, srcChain: params.sourceChain, kind: "order" } })) {
|
|
1941
|
+
return refuse2("the platform reused a quote id that already holds another user's quote");
|
|
1942
|
+
}
|
|
1907
1943
|
const feeUnits = Number(q.protocolFeeUnits || "0") + Number(q.integratorFeeUnits || "0");
|
|
1908
1944
|
const feeUsd = feeUnits / 10 ** dest.decimals;
|
|
1909
1945
|
return {
|
|
@@ -2035,6 +2071,7 @@ function omnistonProvider(opts = {}) {
|
|
|
2035
2071
|
await forget();
|
|
2036
2072
|
throw error;
|
|
2037
2073
|
}
|
|
2074
|
+
await saveBuilt(ref.quoteId, { quote: q, at: Date.now(), ...cached.bound ? { bound: cached.bound } : {} });
|
|
2038
2075
|
return {
|
|
2039
2076
|
chain: srcChain,
|
|
2040
2077
|
to: message.targetAddress,
|
|
@@ -2078,8 +2115,15 @@ function omnistonProvider(opts = {}) {
|
|
|
2078
2115
|
})
|
|
2079
2116
|
);
|
|
2080
2117
|
if (!order) return { state: "pending" };
|
|
2081
|
-
|
|
2118
|
+
let secretsHex = await store.load(decoded.quoteId);
|
|
2082
2119
|
if (!secretsHex || cached?.quote.settlementData.$case !== "order") trace("disclosure-skipped", { gate: "context", secrets: !!secretsHex, cached: !!cached, feedStatus: order.status });
|
|
2120
|
+
if (secretsHex && cached?.quote.settlementData.$case === "order") {
|
|
2121
|
+
const [lockedTo] = await store.load(bindKey(decoded.quoteId)) ?? [];
|
|
2122
|
+
if (lockedTo !== orderBinding(bound, cached.quote)) {
|
|
2123
|
+
trace("disclosure-skipped", { gate: "binding", bound: lockedTo !== void 0, feedStatus: order.status });
|
|
2124
|
+
secretsHex = void 0;
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2083
2127
|
if (secretsHex && cached?.quote.settlementData.$case === "order") {
|
|
2084
2128
|
const q = cached.quote;
|
|
2085
2129
|
const settlement = q.settlementData.value;
|