@anywalletkit/protocol-swap2-omniston 0.3.1 → 0.4.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 +13 -0
- package/dist/chunk-JWYDIW4V.js +37 -0
- package/dist/chunk-JWYDIW4V.js.map +1 -0
- package/dist/{chunk-HOTFZYSW.js → chunk-R6B2CV5Z.js} +153 -42
- package/dist/chunk-R6B2CV5Z.js.map +1 -0
- package/dist/{chunk-RW4XZWNC.js → chunk-WL7BSEBR.js} +2 -2
- package/dist/index.cjs +180 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -2
- package/dist/protocol.cjs +55 -41
- 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 +3 -2
- package/dist/{provider-BBG2zhpu.d.cts → provider-D6RXRgf-.d.cts} +8 -1
- package/dist/{provider-BBG2zhpu.d.ts → provider-D6RXRgf-.d.ts} +8 -1
- package/dist/provider.cjs +180 -41
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.cts +1 -1
- package/dist/provider.d.ts +1 -1
- package/dist/provider.js +2 -1
- package/dist/validators.d.cts +1 -1
- package/dist/validators.d.ts +1 -1
- package/dist/validators.js +5 -34
- package/dist/validators.js.map +1 -1
- package/package.json +5 -5
- package/dist/chunk-HOTFZYSW.js.map +0 -1
- /package/dist/{chunk-RW4XZWNC.js.map → chunk-WL7BSEBR.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { omniston } from './config.cjs';
|
|
2
|
-
export { A as AssetId, C as ChainAddress, E as EscrowMessage, H as HtlcSecretStore, O as ObservableLike, a as OmnistonClientLike, b as OmnistonProviderOptions, c as OmnistonQuote, d as OmnistonQuoteStore, e as OrderEvent, f as OrderExecution, g as OrderSettlement, h as OrderSnapshot, Q as QuoteRequest, R as RfqEvent, S as SwapSettlement, i as SwapTrackEvent, T as TON_SWAP_PROTOCOL_LAYOUTS, j as TonSwapCheckInput, k as TonSwapCheckResult, l as TonSwapLeg, m as TonSwapPayloadError, n as checkTonSwapPayload, o as encodeTypedMessage, p as inMemoryQuoteStore, q as inMemorySecretStore, r as omnistonPins, s as omnistonProvider, t as omnistonVerifyBuild, v as validateEvmToTonOrderExtension, u as validateEvmTypedOrder } from './provider-
|
|
2
|
+
export { A as AssetId, C as ChainAddress, E as EscrowMessage, H as HtlcSecretStore, O as ObservableLike, a as OmnistonClientLike, b as OmnistonProviderOptions, c as OmnistonQuote, d as OmnistonQuoteStore, e as OrderEvent, f as OrderExecution, g as OrderSettlement, h as OrderSnapshot, Q as QuoteRequest, R as RfqEvent, S as SwapSettlement, i as SwapTrackEvent, T as TON_SWAP_PROTOCOL_LAYOUTS, j as TonSwapCheckInput, k as TonSwapCheckResult, l as TonSwapLeg, m as TonSwapPayloadError, n as checkTonSwapPayload, o as encodeTypedMessage, p as inMemoryQuoteStore, q as inMemorySecretStore, r as omnistonPins, s as omnistonProvider, t as omnistonVerifyBuild, v as validateEvmToTonOrderExtension, u as validateEvmTypedOrder } from './provider-D6RXRgf-.cjs';
|
|
3
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';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { omniston } from './config.js';
|
|
2
|
-
export { A as AssetId, C as ChainAddress, E as EscrowMessage, H as HtlcSecretStore, O as ObservableLike, a as OmnistonClientLike, b as OmnistonProviderOptions, c as OmnistonQuote, d as OmnistonQuoteStore, e as OrderEvent, f as OrderExecution, g as OrderSettlement, h as OrderSnapshot, Q as QuoteRequest, R as RfqEvent, S as SwapSettlement, i as SwapTrackEvent, T as TON_SWAP_PROTOCOL_LAYOUTS, j as TonSwapCheckInput, k as TonSwapCheckResult, l as TonSwapLeg, m as TonSwapPayloadError, n as checkTonSwapPayload, o as encodeTypedMessage, p as inMemoryQuoteStore, q as inMemorySecretStore, r as omnistonPins, s as omnistonProvider, t as omnistonVerifyBuild, v as validateEvmToTonOrderExtension, u as validateEvmTypedOrder } from './provider-
|
|
2
|
+
export { A as AssetId, C as ChainAddress, E as EscrowMessage, H as HtlcSecretStore, O as ObservableLike, a as OmnistonClientLike, b as OmnistonProviderOptions, c as OmnistonQuote, d as OmnistonQuoteStore, e as OrderEvent, f as OrderExecution, g as OrderSettlement, h as OrderSnapshot, Q as QuoteRequest, R as RfqEvent, S as SwapSettlement, i as SwapTrackEvent, T as TON_SWAP_PROTOCOL_LAYOUTS, j as TonSwapCheckInput, k as TonSwapCheckResult, l as TonSwapLeg, m as TonSwapPayloadError, n as checkTonSwapPayload, o as encodeTypedMessage, p as inMemoryQuoteStore, q as inMemorySecretStore, r as omnistonPins, s as omnistonProvider, t as omnistonVerifyBuild, v as validateEvmToTonOrderExtension, u as validateEvmTypedOrder } from './provider-D6RXRgf-.js';
|
|
3
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';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OmnistonSwap2Protocol
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-WL7BSEBR.js";
|
|
4
4
|
import {
|
|
5
5
|
TON_SWAP_PROTOCOL_LAYOUTS,
|
|
6
6
|
TonSwapPayloadError,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
omnistonVerifyBuild,
|
|
14
14
|
validateEvmToTonOrderExtension,
|
|
15
15
|
validateEvmTypedOrder
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-R6B2CV5Z.js";
|
|
17
17
|
import {
|
|
18
18
|
omniston
|
|
19
19
|
} from "./chunk-QDXFC6BC.js";
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
STONFI_ROUTERS,
|
|
24
24
|
describeOmnistonActivity
|
|
25
25
|
} from "./chunk-AIWAM7BS.js";
|
|
26
|
+
import "./chunk-JWYDIW4V.js";
|
|
26
27
|
export {
|
|
27
28
|
OMNISTON_ESCROWS,
|
|
28
29
|
OMNISTON_MODULE,
|
package/dist/protocol.cjs
CHANGED
|
@@ -632,9 +632,9 @@ function validEvmAddress(value) {
|
|
|
632
632
|
}
|
|
633
633
|
}
|
|
634
634
|
var EVM_DEST_PROTOCOL_FEE_RECIPIENTS = /* @__PURE__ */ new Set(["0x076268146b4ec6d21fc49c27586cfa91b9079a00"]);
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
635
|
+
var EVM_AUCTION_POINTS = [[800000n, 100n], [700000n, 100n], [600000n, 100n], [500000n, 100n], [400000n, 100n]];
|
|
636
|
+
var EVM_TIMELOCKS = [1n, 120n, 240n, 300n, 1n, 120n, 180n, 0n].reduce((packed, value, index) => packed | value << BigInt(index * 32), 0n);
|
|
637
|
+
function readEvmOrderExtension(extension) {
|
|
638
638
|
if (extension.length < 32) throw new Error("omniston: malformed EVM order extension");
|
|
639
639
|
const view = new DataView(extension.buffer, extension.byteOffset, extension.byteLength);
|
|
640
640
|
const fields = [];
|
|
@@ -654,54 +654,48 @@ async function validateEvmToTonOrderExtension(extension, expected) {
|
|
|
654
654
|
}
|
|
655
655
|
let target;
|
|
656
656
|
for (const index of [2, 3, 7]) {
|
|
657
|
-
const
|
|
658
|
-
if (
|
|
659
|
-
const address = (0, import_viem.getAddress)(`0x${bytesToHex(
|
|
660
|
-
if (
|
|
657
|
+
const field2 = fields[index];
|
|
658
|
+
if (field2.length <= 20) throw new Error("omniston: incomplete EVM order extension program");
|
|
659
|
+
const address = (0, import_viem.getAddress)(`0x${bytesToHex(field2.slice(0, 20))}`);
|
|
660
|
+
if (target !== void 0 && (0, import_viem.getAddress)(target) !== address) {
|
|
661
661
|
throw new Error("omniston: EVM order extension target is not independently trusted");
|
|
662
662
|
}
|
|
663
663
|
target = address;
|
|
664
664
|
}
|
|
665
|
-
const
|
|
665
|
+
const field = fields[2];
|
|
666
666
|
let cursor = 20;
|
|
667
|
-
const gasBump = readBigEndian(
|
|
667
|
+
const gasBump = readBigEndian(field, cursor, 3);
|
|
668
668
|
cursor += 3;
|
|
669
|
-
const gasPrice = readBigEndian(
|
|
669
|
+
const gasPrice = readBigEndian(field, cursor, 4);
|
|
670
670
|
cursor += 4;
|
|
671
|
-
const auctionStart = readBigEndian(
|
|
671
|
+
const auctionStart = readBigEndian(field, cursor, 4);
|
|
672
672
|
cursor += 4;
|
|
673
|
-
const duration = readBigEndian(
|
|
673
|
+
const duration = readBigEndian(field, cursor, 3);
|
|
674
674
|
cursor += 3;
|
|
675
|
-
const initialRateBump = readBigEndian(
|
|
675
|
+
const initialRateBump = readBigEndian(field, cursor, 3);
|
|
676
676
|
cursor += 3;
|
|
677
|
-
const pointCount = (0, import_core4.bigintToNumber)(readBigEndian(
|
|
677
|
+
const pointCount = (0, import_core4.bigintToNumber)(readBigEndian(field, cursor, 1));
|
|
678
678
|
cursor += 1;
|
|
679
679
|
if (pointCount !== 5) throw new Error("omniston: unsupported EVM auction profile");
|
|
680
680
|
const points = [];
|
|
681
681
|
for (let index = 0; index < pointCount; index++) {
|
|
682
|
-
points.push([readBigEndian(
|
|
682
|
+
points.push([readBigEndian(field, cursor, 3), readBigEndian(field, cursor + 3, 2)]);
|
|
683
683
|
cursor += 5;
|
|
684
684
|
}
|
|
685
|
-
const integratorFee = readBigEndian(
|
|
685
|
+
const integratorFee = readBigEndian(field, cursor, 2);
|
|
686
686
|
cursor += 2;
|
|
687
|
-
const integratorShare = readBigEndian(
|
|
687
|
+
const integratorShare = readBigEndian(field, cursor, 1);
|
|
688
688
|
cursor += 1;
|
|
689
|
-
const resolverFee = readBigEndian(
|
|
689
|
+
const resolverFee = readBigEndian(field, cursor, 2);
|
|
690
690
|
cursor += 2;
|
|
691
|
-
const whitelistDiscount = readBigEndian(
|
|
691
|
+
const whitelistDiscount = readBigEndian(field, cursor, 1);
|
|
692
692
|
cursor += 1;
|
|
693
|
-
const getterWhitelistCount = (0, import_core4.bigintToNumber)(readBigEndian(
|
|
693
|
+
const getterWhitelistCount = (0, import_core4.bigintToNumber)(readBigEndian(field, cursor, 1));
|
|
694
694
|
cursor += 1;
|
|
695
|
-
if (getterWhitelistCount !== 1 || cursor + getterWhitelistCount * 10 !==
|
|
695
|
+
if (getterWhitelistCount !== 1 || cursor + getterWhitelistCount * 10 !== field.length) {
|
|
696
696
|
throw new Error("omniston: malformed EVM amount-getter whitelist");
|
|
697
697
|
}
|
|
698
|
-
const
|
|
699
|
-
const expectedPoints = [[800000n, 100n], [700000n, 100n], [600000n, 100n], [500000n, 100n], [400000n, 100n]];
|
|
700
|
-
const quoteResolverFee = expected.protocolFeePips % 10 === 0 ? BigInt(expected.protocolFeePips / 10) : -1n;
|
|
701
|
-
const resolverLow80 = BigInt((0, import_viem.getAddress)(expected.initialResolverAddress)) & (1n << 80n) - 1n;
|
|
702
|
-
if (gasBump !== 0n || gasPrice !== 0n || !within(auctionStart, expected.quoteTimestamp, 5, 5) || duration !== 1800n || initialRateBump !== 900000n || points.some((point, index) => point[0] !== expectedPoints[index][0] || point[1] !== expectedPoints[index][1]) || expected.integratorFeePips !== 0 || integratorFee !== 0n || integratorShare !== 100n || quoteResolverFee < 0n || resolverFee !== quoteResolverFee || whitelistDiscount !== 50n || getterResolver !== resolverLow80) {
|
|
703
|
-
throw new Error("omniston: EVM amount-getter terms do not match the pinned v1beta8 profile");
|
|
704
|
-
}
|
|
698
|
+
const getter = { gasBump, gasPrice, auctionStart, duration, initialRateBump, points, integratorFee, integratorShare, resolverFee, whitelistDiscount, resolver: readBigEndian(field, cursor, 10) };
|
|
705
699
|
const post = fields[7];
|
|
706
700
|
cursor = 20;
|
|
707
701
|
const integratorRecipient = post.slice(cursor, cursor + 20);
|
|
@@ -727,28 +721,51 @@ async function validateEvmToTonOrderExtension(extension, expected) {
|
|
|
727
721
|
cursor += 10;
|
|
728
722
|
const resolverTimeDelta = readBigEndian(post, cursor, 2);
|
|
729
723
|
cursor += 2;
|
|
730
|
-
if (!zeroBytes(integratorRecipient) || !(zeroBytes(protocolRecipient) || evmDest && EVM_DEST_PROTOCOL_FEE_RECIPIENTS.has(`0x${bytesToHex(protocolRecipient)}`)) || postIntegratorFee !== 0n || postIntegratorShare !== 100n || postResolverFee !== quoteResolverFee || postDiscount !== 50n || !within(allowedTime, expected.quoteTimestamp, 60, 5) || postResolver !== resolverLow80 || resolverTimeDelta !== 0n) {
|
|
731
|
-
throw new Error("omniston: EVM post-interaction terms do not match the pinned v1beta8 profile");
|
|
732
|
-
}
|
|
733
724
|
const extra = Array.from({ length: 5 }, () => {
|
|
734
725
|
const value = readBigEndian(post, cursor, 32);
|
|
735
726
|
cursor += 32;
|
|
736
727
|
return value;
|
|
737
728
|
});
|
|
729
|
+
const customData = extension.slice(32 + begin);
|
|
730
|
+
if (customData.length !== 131) throw new Error("omniston: malformed EVM order extension custom data");
|
|
731
|
+
return {
|
|
732
|
+
target,
|
|
733
|
+
getter,
|
|
734
|
+
post: { integratorRecipient, protocolRecipient, integratorFee: postIntegratorFee, integratorShare: postIntegratorShare, resolverFee: postResolverFee, discount: postDiscount, allowedTime, resolver: postResolver, resolverTimeDelta },
|
|
735
|
+
extra,
|
|
736
|
+
customData
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
async function validateEvmToTonOrderExtension(extension, expected) {
|
|
740
|
+
const evmDest = expected.dstChainId !== void 0;
|
|
741
|
+
if (evmDest && (!Number.isSafeInteger(expected.dstChainId) || expected.dstChainId <= 0)) throw new Error("omniston: invalid EVM destination chain id");
|
|
742
|
+
const { target, getter, post, extra, customData } = readEvmOrderExtension(extension);
|
|
743
|
+
if (!expected.trustedTarget(target)) throw new Error("omniston: EVM order extension target is not independently trusted");
|
|
744
|
+
const quoteResolverFee = expected.protocolFeePips % 10 === 0 ? BigInt(expected.protocolFeePips / 10) : -1n;
|
|
745
|
+
const resolverLow80 = BigInt((0, import_viem.getAddress)(expected.initialResolverAddress)) & (1n << 80n) - 1n;
|
|
746
|
+
if (getter.gasBump !== 0n || getter.gasPrice !== 0n || !within(getter.auctionStart, expected.quoteTimestamp, 5, 5) || getter.duration !== 1800n || getter.initialRateBump !== 900000n || getter.points.some((point, index) => point[0] !== EVM_AUCTION_POINTS[index][0] || point[1] !== EVM_AUCTION_POINTS[index][1]) || expected.integratorFeePips !== 0 || getter.integratorFee !== 0n || getter.integratorShare !== 100n || quoteResolverFee < 0n || getter.resolverFee !== quoteResolverFee || getter.whitelistDiscount !== 50n || getter.resolver !== resolverLow80) {
|
|
747
|
+
throw new Error("omniston: EVM amount-getter terms do not match the pinned v1beta8 profile");
|
|
748
|
+
}
|
|
749
|
+
if (!zeroBytes(post.integratorRecipient) || !(zeroBytes(post.protocolRecipient) || evmDest && EVM_DEST_PROTOCOL_FEE_RECIPIENTS.has(`0x${bytesToHex(post.protocolRecipient)}`)) || post.integratorFee !== 0n || post.integratorShare !== 100n || post.resolverFee !== quoteResolverFee || post.discount !== 50n || !within(post.allowedTime, expected.quoteTimestamp, 60, 5) || post.resolver !== resolverLow80 || post.resolverTimeDelta !== 0n) {
|
|
750
|
+
throw new Error("omniston: EVM post-interaction terms do not match the pinned v1beta8 profile");
|
|
751
|
+
}
|
|
738
752
|
const hashlock2 = readBigEndian(expected.secretHash, 0, expected.secretHash.length);
|
|
739
753
|
const dstToken = evmDest ? BigInt((0, import_viem.getAddress)(expected.outputTokenAddress)) : BigInt((0, import_viem.getAddress)(expected.takerAsset));
|
|
740
754
|
const deposits = BigInt(expected.srcSecurityDepositUnits) << 128n | BigInt(expected.dstSecurityDepositUnits);
|
|
741
|
-
|
|
742
|
-
if (expected.secretHash.length !== 32 || extra[0] !== hashlock2 || extra[1] !== (evmDest ? BigInt(expected.dstChainId) : 0n) || extra[2] !== dstToken || extra[3] !== deposits || extra[4] !== timelocks) {
|
|
755
|
+
if (expected.secretHash.length !== 32 || extra[0] !== hashlock2 || extra[1] !== (evmDest ? BigInt(expected.dstChainId) : 0n) || extra[2] !== dstToken || extra[3] !== deposits || extra[4] !== EVM_TIMELOCKS) {
|
|
743
756
|
throw new Error("omniston: signed EVM HTLC terms do not match the validated order details");
|
|
744
757
|
}
|
|
745
|
-
|
|
746
|
-
if (
|
|
747
|
-
|
|
758
|
+
await checkOrderCustomData(customData, { evmDest, outputToken: expected.outputTokenAddress, traderDst: expected.traderDstAddress, quoteId: expected.quoteId });
|
|
759
|
+
if (expected.tradeStartDeadline < expected.quoteTimestamp) {
|
|
760
|
+
throw new Error("omniston: invalid EVM order quote deadline");
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
async function checkOrderCustomData(customData, expected) {
|
|
764
|
+
if (expected.evmDest) {
|
|
748
765
|
if (!zeroBytes(customData.slice(0, 66))) throw new Error("omniston: unexpected TON addresses in an EVM-destination order");
|
|
749
766
|
} else {
|
|
750
767
|
const { Address: Address3 } = await import("@ton/core");
|
|
751
|
-
const expectedTon = [expected.
|
|
768
|
+
const expectedTon = [expected.outputToken, expected.traderDst].map((value) => Address3.parse(value));
|
|
752
769
|
for (let index = 0; index < expectedTon.length; index++) {
|
|
753
770
|
const offset = index * 33;
|
|
754
771
|
const workchain = customData[offset] === 255 ? -1 : customData[offset];
|
|
@@ -764,9 +781,6 @@ async function validateEvmToTonOrderExtension(extension, expected) {
|
|
|
764
781
|
if (!QUOTE_ID.test(quoteId) || !sliceEqual(customData.slice(99), hexToBytes(quoteId.padStart(64, "0")))) {
|
|
765
782
|
throw new Error("omniston: EVM order extension custom data is not bound to the quote id");
|
|
766
783
|
}
|
|
767
|
-
if (expected.tradeStartDeadline < expected.quoteTimestamp) {
|
|
768
|
-
throw new Error("omniston: invalid EVM order quote deadline");
|
|
769
|
-
}
|
|
770
784
|
}
|
|
771
785
|
function validateEvmTypedOrder(td, expected) {
|
|
772
786
|
const value = td;
|
|
@@ -1829,7 +1843,7 @@ function omnistonProvider(opts = {}) {
|
|
|
1829
1843
|
}
|
|
1830
1844
|
});
|
|
1831
1845
|
const orderProtocol = (0, import_viem.getAddress)(protocol.chain.value);
|
|
1832
|
-
return { chain: srcChain, to: orderProtocol, value: "0", chainId, approvalAddress: orderProtocol, typedData };
|
|
1846
|
+
return { chain: srcChain, to: orderProtocol, value: "0", chainId, approvalAddress: orderProtocol, typedData, orderExtension: `0x${bytesToHex(payload.orderExtension)}` };
|
|
1833
1847
|
}
|
|
1834
1848
|
return {
|
|
1835
1849
|
name: "omniston",
|