@stryke-xyz/premarket-sdk 1.0.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/dist/abi/AggregationRouterV6.abi.json +1186 -0
- package/dist/abi/NativeOrderFactory.abi.json +291 -0
- package/dist/abi/NativeOrderImpl.abi.json +381 -0
- package/dist/abi/limitOrderProtocol.json +63 -0
- package/dist/address.d.ts +13 -0
- package/dist/address.js +32 -0
- package/dist/api/filler.d.ts +109 -0
- package/dist/api/filler.js +289 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +3 -0
- package/dist/api/order-helper.d.ts +59 -0
- package/dist/api/order-helper.js +112 -0
- package/dist/api/orderbook-api.d.ts +36 -0
- package/dist/api/orderbook-api.js +69 -0
- package/dist/bps.d.ts +35 -0
- package/dist/bps.js +52 -0
- package/dist/config/chains.d.ts +50 -0
- package/dist/config/chains.js +21 -0
- package/dist/config/index.d.ts +25 -0
- package/dist/config/index.js +103 -0
- package/dist/config/markets.d.ts +53 -0
- package/dist/config/markets.js +125 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +30 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +21 -0
- package/dist/limit-order/amounts.d.ts +14 -0
- package/dist/limit-order/amounts.js +19 -0
- package/dist/limit-order/eip712/domain.d.ts +10 -0
- package/dist/limit-order/eip712/domain.js +18 -0
- package/dist/limit-order/eip712/eip712.types.d.ts +23 -0
- package/dist/limit-order/eip712/eip712.types.js +1 -0
- package/dist/limit-order/eip712/index.d.ts +3 -0
- package/dist/limit-order/eip712/index.js +3 -0
- package/dist/limit-order/eip712/order-typed-data-builder.d.ts +6 -0
- package/dist/limit-order/eip712/order-typed-data-builder.js +25 -0
- package/dist/limit-order/extensions/extension-builder.d.ts +35 -0
- package/dist/limit-order/extensions/extension-builder.js +83 -0
- package/dist/limit-order/extensions/extension.d.ts +45 -0
- package/dist/limit-order/extensions/extension.js +108 -0
- package/dist/limit-order/extensions/extension.spec.d.ts +1 -0
- package/dist/limit-order/extensions/extension.spec.js +17 -0
- package/dist/limit-order/extensions/fee-taker/errors.d.ts +2 -0
- package/dist/limit-order/extensions/fee-taker/errors.js +2 -0
- package/dist/limit-order/extensions/fee-taker/fee-calculator.d.ts +40 -0
- package/dist/limit-order/extensions/fee-taker/fee-calculator.js +83 -0
- package/dist/limit-order/extensions/fee-taker/fee-calculator.spec.d.ts +1 -0
- package/dist/limit-order/extensions/fee-taker/fee-calculator.spec.js +14 -0
- package/dist/limit-order/extensions/fee-taker/fee-taker.extension.d.ts +130 -0
- package/dist/limit-order/extensions/fee-taker/fee-taker.extension.js +249 -0
- package/dist/limit-order/extensions/fee-taker/fee-taker.extension.spec.d.ts +1 -0
- package/dist/limit-order/extensions/fee-taker/fee-taker.extension.spec.js +72 -0
- package/dist/limit-order/extensions/fee-taker/fees.d.ts +19 -0
- package/dist/limit-order/extensions/fee-taker/fees.js +36 -0
- package/dist/limit-order/extensions/fee-taker/index.d.ts +7 -0
- package/dist/limit-order/extensions/fee-taker/index.js +7 -0
- package/dist/limit-order/extensions/fee-taker/integrator-fee.d.ts +13 -0
- package/dist/limit-order/extensions/fee-taker/integrator-fee.js +28 -0
- package/dist/limit-order/extensions/fee-taker/resolver-fee.d.ts +19 -0
- package/dist/limit-order/extensions/fee-taker/resolver-fee.js +28 -0
- package/dist/limit-order/extensions/fee-taker/types.d.ts +4 -0
- package/dist/limit-order/extensions/fee-taker/types.js +1 -0
- package/dist/limit-order/extensions/fee-taker/whitelist-half-address.d.ts +18 -0
- package/dist/limit-order/extensions/fee-taker/whitelist-half-address.js +26 -0
- package/dist/limit-order/extensions/index.d.ts +3 -0
- package/dist/limit-order/extensions/index.js +3 -0
- package/dist/limit-order/index.d.ts +10 -0
- package/dist/limit-order/index.js +10 -0
- package/dist/limit-order/interaction.d.ts +16 -0
- package/dist/limit-order/interaction.js +25 -0
- package/dist/limit-order/interaction.spec.d.ts +1 -0
- package/dist/limit-order/interaction.spec.js +8 -0
- package/dist/limit-order/limit-order-with-fee.d.ts +59 -0
- package/dist/limit-order/limit-order-with-fee.js +94 -0
- package/dist/limit-order/limit-order-with-fee.spec.d.ts +1 -0
- package/dist/limit-order/limit-order-with-fee.spec.js +31 -0
- package/dist/limit-order/limit-order.d.ts +63 -0
- package/dist/limit-order/limit-order.js +211 -0
- package/dist/limit-order/limit-order.spec.d.ts +1 -0
- package/dist/limit-order/limit-order.spec.js +103 -0
- package/dist/limit-order/maker-traits.d.ts +200 -0
- package/dist/limit-order/maker-traits.js +309 -0
- package/dist/limit-order/maker-traits.spec.d.ts +1 -0
- package/dist/limit-order/maker-traits.spec.js +102 -0
- package/dist/limit-order/source-track.d.ts +1 -0
- package/dist/limit-order/source-track.js +22 -0
- package/dist/limit-order/taker-traits.d.ts +141 -0
- package/dist/limit-order/taker-traits.js +207 -0
- package/dist/limit-order/types.d.ts +24 -0
- package/dist/limit-order/types.js +1 -0
- package/dist/limit-order/verification.d.ts +16 -0
- package/dist/limit-order/verification.js +108 -0
- package/dist/limit-order-contract/index.d.ts +4 -0
- package/dist/limit-order-contract/index.js +4 -0
- package/dist/limit-order-contract/limit-order-contract.d.ts +34 -0
- package/dist/limit-order-contract/limit-order-contract.js +79 -0
- package/dist/limit-order-contract/native-order-factory.d.ts +10 -0
- package/dist/limit-order-contract/native-order-factory.js +22 -0
- package/dist/limit-order-contract/native-order-impl.d.ts +10 -0
- package/dist/limit-order-contract/native-order-impl.js +24 -0
- package/dist/limit-order-contract/proxy-factory.d.ts +20 -0
- package/dist/limit-order-contract/proxy-factory.js +32 -0
- package/dist/limit-order-contract/proxy-factory.spec.d.ts +1 -0
- package/dist/limit-order-contract/proxy-factory.spec.js +16 -0
- package/dist/limit-order-contract/types.d.ts +6 -0
- package/dist/limit-order-contract/types.js +1 -0
- package/dist/ponder/client/index.d.ts +23 -0
- package/dist/ponder/client/index.js +44 -0
- package/dist/ponder/client/queries/markets.d.ts +30 -0
- package/dist/ponder/client/queries/markets.js +200 -0
- package/dist/ponder/client/queries/positions.d.ts +13 -0
- package/dist/ponder/client/queries/positions.js +406 -0
- package/dist/ponder/client/types/history.d.ts +94 -0
- package/dist/ponder/client/types/history.js +1 -0
- package/dist/ponder/client/types/index.d.ts +5 -0
- package/dist/ponder/client/types/index.js +5 -0
- package/dist/ponder/client/types/market.d.ts +45 -0
- package/dist/ponder/client/types/market.js +1 -0
- package/dist/ponder/client/types/position.d.ts +32 -0
- package/dist/ponder/client/types/position.js +1 -0
- package/dist/ponder/client/types/serializers.d.ts +57 -0
- package/dist/ponder/client/types/serializers.js +248 -0
- package/dist/ponder/client/types/user.d.ts +5 -0
- package/dist/ponder/client/types/user.js +1 -0
- package/dist/ponder/client/utils.d.ts +1 -0
- package/dist/ponder/client/utils.js +32 -0
- package/dist/ponder/generated/index.d.ts +18 -0
- package/dist/ponder/generated/index.js +20 -0
- package/dist/ponder/generated/runtime/batcher.d.ts +105 -0
- package/dist/ponder/generated/runtime/batcher.js +188 -0
- package/dist/ponder/generated/runtime/createClient.d.ts +17 -0
- package/dist/ponder/generated/runtime/createClient.js +24 -0
- package/dist/ponder/generated/runtime/error.d.ts +18 -0
- package/dist/ponder/generated/runtime/error.js +15 -0
- package/dist/ponder/generated/runtime/fetcher.d.ts +10 -0
- package/dist/ponder/generated/runtime/fetcher.js +67 -0
- package/dist/ponder/generated/runtime/generateGraphqlOperation.d.ts +30 -0
- package/dist/ponder/generated/runtime/generateGraphqlOperation.js +128 -0
- package/dist/ponder/generated/runtime/index.d.ts +11 -0
- package/dist/ponder/generated/runtime/index.js +10 -0
- package/dist/ponder/generated/runtime/linkTypeMap.d.ts +9 -0
- package/dist/ponder/generated/runtime/linkTypeMap.js +83 -0
- package/dist/ponder/generated/runtime/typeSelection.d.ts +28 -0
- package/dist/ponder/generated/runtime/typeSelection.js +3 -0
- package/dist/ponder/generated/runtime/types.d.ts +55 -0
- package/dist/ponder/generated/runtime/types.js +2 -0
- package/dist/ponder/generated/schema.d.ts +3026 -0
- package/dist/ponder/generated/schema.js +222 -0
- package/dist/ponder/generated/types.d.ts +2393 -0
- package/dist/ponder/generated/types.js +6915 -0
- package/dist/ponder/index.d.ts +2 -0
- package/dist/ponder/index.js +2 -0
- package/dist/ponder/types.d.ts +3 -0
- package/dist/ponder/types.js +1 -0
- package/dist/rfq-order/index.d.ts +1 -0
- package/dist/rfq-order/index.js +1 -0
- package/dist/rfq-order/rfq-order.d.ts +21 -0
- package/dist/rfq-order/rfq-order.js +22 -0
- package/dist/rfq-order/rfq-order.spec.d.ts +1 -0
- package/dist/rfq-order/rfq-order.spec.js +27 -0
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.js +2 -0
- package/dist/shared/types.d.ts +79 -0
- package/dist/shared/types.js +12 -0
- package/dist/shared/utils.d.ts +7 -0
- package/dist/shared/utils.js +19 -0
- package/dist/sync/clients/balance-client.d.ts +41 -0
- package/dist/sync/clients/balance-client.js +139 -0
- package/dist/sync/clients/base-client.d.ts +47 -0
- package/dist/sync/clients/base-client.js +154 -0
- package/dist/sync/clients/order-client.d.ts +18 -0
- package/dist/sync/clients/order-client.js +151 -0
- package/dist/sync/index.d.ts +5 -0
- package/dist/sync/index.js +3 -0
- package/dist/sync/redis-ws-client.d.ts +18 -0
- package/dist/sync/redis-ws-client.js +88 -0
- package/dist/sync/types.d.ts +20 -0
- package/dist/sync/types.js +1 -0
- package/dist/utils/mul-div.d.ts +5 -0
- package/dist/utils/mul-div.js +13 -0
- package/dist/utils/orderUtils.d.ts +19 -0
- package/dist/utils/orderUtils.js +51 -0
- package/dist/utils/rand-bigint.d.ts +1 -0
- package/dist/utils/rand-bigint.js +13 -0
- package/dist/utils/rand-bigint.spec.d.ts +1 -0
- package/dist/utils/rand-bigint.spec.js +11 -0
- package/dist/validations.d.ts +1 -0
- package/dist/validations.js +3 -0
- package/package.json +60 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { UINT_160_MAX, UINT_40_MAX } from '@1inch/byte-utils';
|
|
2
|
+
import { MakerTraits } from './maker-traits.js';
|
|
3
|
+
import { Address } from '../address.js';
|
|
4
|
+
describe('MakerTraits', () => {
|
|
5
|
+
test('allowed sender', () => {
|
|
6
|
+
const traits = MakerTraits.default();
|
|
7
|
+
const sender = Address.fromBigInt(1337n);
|
|
8
|
+
const senderHalf = traits.withAllowedSender(sender).allowedSender();
|
|
9
|
+
expect(senderHalf).toEqual(sender.toString().slice(-20));
|
|
10
|
+
});
|
|
11
|
+
test('nonce', () => {
|
|
12
|
+
const traits = MakerTraits.default();
|
|
13
|
+
const nonce = 1n << 10n;
|
|
14
|
+
traits.withNonce(nonce);
|
|
15
|
+
expect(traits.nonceOrEpoch()).toEqual(nonce);
|
|
16
|
+
const big_nonce = 1n << 50n;
|
|
17
|
+
expect(() => traits.withNonce(big_nonce)).toThrow('to big for mask');
|
|
18
|
+
});
|
|
19
|
+
test('expiration', () => {
|
|
20
|
+
const traits = MakerTraits.default();
|
|
21
|
+
const expiration = 1000000n;
|
|
22
|
+
traits.withExpiration(expiration);
|
|
23
|
+
expect(traits.expiration()).toEqual(expiration);
|
|
24
|
+
});
|
|
25
|
+
test('epoch', () => {
|
|
26
|
+
const traits = MakerTraits.default();
|
|
27
|
+
const series = 100n;
|
|
28
|
+
const epoch = 1n;
|
|
29
|
+
traits.allowPartialFills().allowMultipleFills().withEpoch(series, epoch);
|
|
30
|
+
expect(traits.series()).toEqual(series);
|
|
31
|
+
expect(traits.nonceOrEpoch()).toEqual(epoch);
|
|
32
|
+
expect(traits.isEpochManagerEnabled()).toEqual(true);
|
|
33
|
+
});
|
|
34
|
+
test('extension', () => {
|
|
35
|
+
const traits = MakerTraits.default();
|
|
36
|
+
expect(traits.hasExtension()).toEqual(false);
|
|
37
|
+
traits.withExtension();
|
|
38
|
+
expect(traits.hasExtension()).toEqual(true);
|
|
39
|
+
});
|
|
40
|
+
test('partial fills', () => {
|
|
41
|
+
const traits = MakerTraits.default();
|
|
42
|
+
expect(traits.isPartialFillAllowed()).toEqual(true);
|
|
43
|
+
traits.disablePartialFills();
|
|
44
|
+
expect(traits.isPartialFillAllowed()).toEqual(false);
|
|
45
|
+
traits.allowPartialFills();
|
|
46
|
+
expect(traits.isPartialFillAllowed()).toEqual(true);
|
|
47
|
+
});
|
|
48
|
+
test('multiple fills', () => {
|
|
49
|
+
const traits = MakerTraits.default();
|
|
50
|
+
expect(traits.isMultipleFillsAllowed()).toEqual(false);
|
|
51
|
+
traits.allowMultipleFills();
|
|
52
|
+
expect(traits.isMultipleFillsAllowed()).toEqual(true);
|
|
53
|
+
traits.disableMultipleFills();
|
|
54
|
+
expect(traits.isMultipleFillsAllowed()).toEqual(false);
|
|
55
|
+
});
|
|
56
|
+
test('pre interaction', () => {
|
|
57
|
+
const traits = MakerTraits.default();
|
|
58
|
+
expect(traits.hasPreInteraction()).toEqual(false);
|
|
59
|
+
traits.enablePreInteraction();
|
|
60
|
+
expect(traits.hasPreInteraction()).toEqual(true);
|
|
61
|
+
traits.disablePreInteraction();
|
|
62
|
+
expect(traits.hasPreInteraction()).toEqual(false);
|
|
63
|
+
});
|
|
64
|
+
test('post interaction', () => {
|
|
65
|
+
const traits = MakerTraits.default();
|
|
66
|
+
expect(traits.hasPostInteraction()).toEqual(false);
|
|
67
|
+
traits.enablePostInteraction();
|
|
68
|
+
expect(traits.hasPostInteraction()).toEqual(true);
|
|
69
|
+
traits.disablePostInteraction();
|
|
70
|
+
expect(traits.hasPostInteraction()).toEqual(false);
|
|
71
|
+
});
|
|
72
|
+
test('permit2', () => {
|
|
73
|
+
const traits = MakerTraits.default();
|
|
74
|
+
expect(traits.isPermit2()).toEqual(false);
|
|
75
|
+
traits.enablePermit2();
|
|
76
|
+
expect(traits.isPermit2()).toEqual(true);
|
|
77
|
+
traits.disablePermit2();
|
|
78
|
+
expect(traits.isPermit2()).toEqual(false);
|
|
79
|
+
});
|
|
80
|
+
test('native unwrap', () => {
|
|
81
|
+
const traits = MakerTraits.default();
|
|
82
|
+
expect(traits.isNativeUnwrapEnabled()).toEqual(false);
|
|
83
|
+
traits.enableNativeUnwrap();
|
|
84
|
+
expect(traits.isNativeUnwrapEnabled()).toEqual(true);
|
|
85
|
+
traits.disableNativeUnwrap();
|
|
86
|
+
expect(traits.isNativeUnwrapEnabled()).toEqual(false);
|
|
87
|
+
});
|
|
88
|
+
test('all', () => {
|
|
89
|
+
const traits = MakerTraits.default()
|
|
90
|
+
.withAllowedSender(Address.fromBigInt(UINT_160_MAX))
|
|
91
|
+
.allowPartialFills()
|
|
92
|
+
.allowMultipleFills()
|
|
93
|
+
.withEpoch(UINT_40_MAX, UINT_40_MAX)
|
|
94
|
+
.withExpiration(UINT_40_MAX)
|
|
95
|
+
.withExtension()
|
|
96
|
+
.enablePermit2()
|
|
97
|
+
.enableNativeUnwrap()
|
|
98
|
+
.enablePreInteraction()
|
|
99
|
+
.enablePostInteraction();
|
|
100
|
+
expect(traits.asBigInt().toString(16)).toEqual('5f800000000000ffffffffffffffffffffffffffffffffffffffffffffffffff');
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function injectTrackCode(salt: bigint, source?: string): bigint;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { add0x, BitMask, BN, isHexString } from '@1inch/byte-utils';
|
|
2
|
+
import { id } from 'ethers';
|
|
3
|
+
const TRACK_CODE_MASK = new BitMask(224n, 256n);
|
|
4
|
+
function getTrackCodeForSource(source) {
|
|
5
|
+
if (!isHexString(source)) {
|
|
6
|
+
return createId(source);
|
|
7
|
+
}
|
|
8
|
+
if (source.length === 10) {
|
|
9
|
+
return BigInt(source);
|
|
10
|
+
}
|
|
11
|
+
if (source.length === 66) {
|
|
12
|
+
return BigInt(source.substring(0, 10));
|
|
13
|
+
}
|
|
14
|
+
return createId(source);
|
|
15
|
+
}
|
|
16
|
+
function createId(source) {
|
|
17
|
+
return BigInt(add0x(id(source).slice(0, 10)));
|
|
18
|
+
}
|
|
19
|
+
export function injectTrackCode(salt, source) {
|
|
20
|
+
const track = source ? getTrackCodeForSource(source) : 0n;
|
|
21
|
+
return new BN(salt).setMask(TRACK_CODE_MASK, track).value;
|
|
22
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Extension } from './extensions/extension.js';
|
|
2
|
+
import { Interaction } from './interaction.js';
|
|
3
|
+
import { Address } from '../address.js';
|
|
4
|
+
export declare enum AmountMode {
|
|
5
|
+
/**
|
|
6
|
+
* Amount provided to fill function treated as `takingAmount` and `makingAmount` calculated based on it
|
|
7
|
+
*/
|
|
8
|
+
taker = 0,
|
|
9
|
+
/**
|
|
10
|
+
* Amount provided to fill function treated as `makingAmount` and `takingAmount` calculated based on it
|
|
11
|
+
*/
|
|
12
|
+
maker = 1
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* TakerTraitsLib
|
|
16
|
+
* This class defines TakerTraits, which are used to encode the taker's preferences for an order in a single uint256.
|
|
17
|
+
*
|
|
18
|
+
* The TakerTraits are structured as follows:
|
|
19
|
+
* High bits are used for flags
|
|
20
|
+
* 255 bit `_MAKER_AMOUNT_FLAG` - If set, the taking amount is calculated based on making amount, otherwise making amount is calculated based on taking amount.
|
|
21
|
+
* 254 bit `_UNWRAP_WETH_FLAG` - If set, the WETH will be unwrapped into ETH before sending to taker.
|
|
22
|
+
* 253 bit `_SKIP_ORDER_PERMIT_FLAG` - If set, the order skips maker's permit execution.
|
|
23
|
+
* 252 bit `_USE_PERMIT2_FLAG` - If set, the order uses the permit2 function for authorization.
|
|
24
|
+
* 251 bit `_ARGS_HAS_TARGET` - If set, then first 20 bytes of args are treated as receiver address for maker’s funds transfer.
|
|
25
|
+
* 224-247 bits `ARGS_EXTENSION_LENGTH` - The length of the extension calldata in the args.
|
|
26
|
+
* 200-223 bits `ARGS_INTERACTION_LENGTH` - The length of the interaction calldata in the args.
|
|
27
|
+
* 0-184 bits - The threshold amount (the maximum amount a taker agrees to give in exchange for a making amount).
|
|
28
|
+
*/
|
|
29
|
+
export declare class TakerTraits {
|
|
30
|
+
private static MAKER_AMOUNT_FLAG;
|
|
31
|
+
private static UNWRAP_WETH_FLAG;
|
|
32
|
+
private static SKIP_ORDER_PERMIT_FLAG;
|
|
33
|
+
private static USE_PERMIT2_FLAG;
|
|
34
|
+
private static ARGS_HAS_RECEIVER;
|
|
35
|
+
private static THRESHOLD_MASK;
|
|
36
|
+
private static ARGS_INTERACTION_LENGTH_MASK;
|
|
37
|
+
private static ARGS_EXTENSION_LENGTH_MASK;
|
|
38
|
+
private flags;
|
|
39
|
+
private receiver?;
|
|
40
|
+
private extension?;
|
|
41
|
+
private interaction?;
|
|
42
|
+
constructor(flag: bigint, data: {
|
|
43
|
+
receiver?: Address;
|
|
44
|
+
extension?: Extension;
|
|
45
|
+
interaction?: Interaction;
|
|
46
|
+
});
|
|
47
|
+
static default(): TakerTraits;
|
|
48
|
+
/**
|
|
49
|
+
* Returns enabled amount mode, it defines how to treat passed amount in `fillContractOrderArgs` function
|
|
50
|
+
*
|
|
51
|
+
* @see AmountMode
|
|
52
|
+
*/
|
|
53
|
+
getAmountMode(): AmountMode;
|
|
54
|
+
setAmountMode(mode: AmountMode): this;
|
|
55
|
+
/**
|
|
56
|
+
* Is the Wrapped native currency will be unwrapped into Native currency before sending to taker
|
|
57
|
+
*/
|
|
58
|
+
isNativeUnwrapEnabled(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Wrapped native currency will be unwrapped into Native currency before sending to taker
|
|
61
|
+
*/
|
|
62
|
+
enableNativeUnwrap(): this;
|
|
63
|
+
/**
|
|
64
|
+
* Wrapped native currency will NOT be unwrapped into Native currency before sending to taker
|
|
65
|
+
*/
|
|
66
|
+
disableNativeUnwrap(): this;
|
|
67
|
+
/**
|
|
68
|
+
* If true, then maker's permit execution is skipped
|
|
69
|
+
*/
|
|
70
|
+
isOrderPermitSkipped(): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* The order skips maker's permit execution
|
|
73
|
+
*/
|
|
74
|
+
skipOrderPermit(): this;
|
|
75
|
+
/**
|
|
76
|
+
* Should use permit2 function for authorization or not
|
|
77
|
+
*
|
|
78
|
+
* @see https://github.com/Uniswap/permit2
|
|
79
|
+
*/
|
|
80
|
+
isPermit2Enabled(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Use permit2 function for authorization
|
|
83
|
+
*
|
|
84
|
+
* @see https://github.com/Uniswap/permit2
|
|
85
|
+
*/
|
|
86
|
+
enablePermit2(): this;
|
|
87
|
+
/**
|
|
88
|
+
* NOT use permit2 function for authorization
|
|
89
|
+
*/
|
|
90
|
+
disablePermit2(): this;
|
|
91
|
+
/**
|
|
92
|
+
* Sets address where order filled to, `msg.sender` used if not set
|
|
93
|
+
*
|
|
94
|
+
* @param receiver
|
|
95
|
+
*/
|
|
96
|
+
setReceiver(receiver: Address): this;
|
|
97
|
+
/**
|
|
98
|
+
* Set order receiver as `msg.sender`
|
|
99
|
+
*/
|
|
100
|
+
removeReceiver(): this;
|
|
101
|
+
/**
|
|
102
|
+
* Sets extension, it is required to provide same extension as in order creation (if any)
|
|
103
|
+
*/
|
|
104
|
+
setExtension(ext: Extension): this;
|
|
105
|
+
removeExtension(): this;
|
|
106
|
+
/**
|
|
107
|
+
* Set threshold amount
|
|
108
|
+
*
|
|
109
|
+
* In taker amount mode: the minimum amount a taker agrees to receive in exchange for a taking amount.
|
|
110
|
+
* In maker amount mode: the maximum amount a taker agrees to give in exchange for a making amount.
|
|
111
|
+
*
|
|
112
|
+
* @see AmountMode
|
|
113
|
+
*/
|
|
114
|
+
setAmountThreshold(threshold: bigint): this;
|
|
115
|
+
/**
|
|
116
|
+
* Get threshold amount
|
|
117
|
+
*
|
|
118
|
+
* In taker amount mode: the minimum amount a taker agrees to receive in exchange for a taking amount.
|
|
119
|
+
* In maker amount mode: the maximum amount a taker agrees to give in exchange for a making amount.
|
|
120
|
+
*
|
|
121
|
+
* @see AmountMode
|
|
122
|
+
*/
|
|
123
|
+
getAmountThreshold(): bigint;
|
|
124
|
+
/**
|
|
125
|
+
* @see setAmountThreshold
|
|
126
|
+
*/
|
|
127
|
+
removeAmountThreshold(): this;
|
|
128
|
+
/**
|
|
129
|
+
* Sets taker interaction
|
|
130
|
+
*
|
|
131
|
+
* `interaction.target` should implement `ITakerInteraction` interface
|
|
132
|
+
*
|
|
133
|
+
* @see https://github.com/1inch/limit-order-protocol/blob/1a32e059f78ddcf1fe6294baed6cafb73a04b685/contracts/interfaces/ITakerInteraction.sol#L11
|
|
134
|
+
*/
|
|
135
|
+
setInteraction(interaction: Interaction): this;
|
|
136
|
+
removeInteraction(): this;
|
|
137
|
+
encode(): {
|
|
138
|
+
trait: bigint;
|
|
139
|
+
args: string;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { BitMask, BN, getBytesCount, trim0x } from '@1inch/byte-utils';
|
|
2
|
+
import { ZX } from '../constants.js';
|
|
3
|
+
export var AmountMode;
|
|
4
|
+
(function (AmountMode) {
|
|
5
|
+
/**
|
|
6
|
+
* Amount provided to fill function treated as `takingAmount` and `makingAmount` calculated based on it
|
|
7
|
+
*/
|
|
8
|
+
AmountMode[AmountMode["taker"] = 0] = "taker";
|
|
9
|
+
/**
|
|
10
|
+
* Amount provided to fill function treated as `makingAmount` and `takingAmount` calculated based on it
|
|
11
|
+
*/
|
|
12
|
+
AmountMode[AmountMode["maker"] = 1] = "maker";
|
|
13
|
+
})(AmountMode || (AmountMode = {}));
|
|
14
|
+
/**
|
|
15
|
+
* TakerTraitsLib
|
|
16
|
+
* This class defines TakerTraits, which are used to encode the taker's preferences for an order in a single uint256.
|
|
17
|
+
*
|
|
18
|
+
* The TakerTraits are structured as follows:
|
|
19
|
+
* High bits are used for flags
|
|
20
|
+
* 255 bit `_MAKER_AMOUNT_FLAG` - If set, the taking amount is calculated based on making amount, otherwise making amount is calculated based on taking amount.
|
|
21
|
+
* 254 bit `_UNWRAP_WETH_FLAG` - If set, the WETH will be unwrapped into ETH before sending to taker.
|
|
22
|
+
* 253 bit `_SKIP_ORDER_PERMIT_FLAG` - If set, the order skips maker's permit execution.
|
|
23
|
+
* 252 bit `_USE_PERMIT2_FLAG` - If set, the order uses the permit2 function for authorization.
|
|
24
|
+
* 251 bit `_ARGS_HAS_TARGET` - If set, then first 20 bytes of args are treated as receiver address for maker’s funds transfer.
|
|
25
|
+
* 224-247 bits `ARGS_EXTENSION_LENGTH` - The length of the extension calldata in the args.
|
|
26
|
+
* 200-223 bits `ARGS_INTERACTION_LENGTH` - The length of the interaction calldata in the args.
|
|
27
|
+
* 0-184 bits - The threshold amount (the maximum amount a taker agrees to give in exchange for a making amount).
|
|
28
|
+
*/
|
|
29
|
+
export class TakerTraits {
|
|
30
|
+
constructor(flag, data) {
|
|
31
|
+
this.flags = new BN(flag);
|
|
32
|
+
this.receiver = data.receiver;
|
|
33
|
+
this.extension = data.extension;
|
|
34
|
+
this.interaction = data.interaction;
|
|
35
|
+
}
|
|
36
|
+
static default() {
|
|
37
|
+
return new TakerTraits(0n, {});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns enabled amount mode, it defines how to treat passed amount in `fillContractOrderArgs` function
|
|
41
|
+
*
|
|
42
|
+
* @see AmountMode
|
|
43
|
+
*/
|
|
44
|
+
getAmountMode() {
|
|
45
|
+
return this.flags.getBit(TakerTraits.MAKER_AMOUNT_FLAG);
|
|
46
|
+
}
|
|
47
|
+
setAmountMode(mode) {
|
|
48
|
+
this.flags = this.flags.setBit(TakerTraits.MAKER_AMOUNT_FLAG, mode);
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Is the Wrapped native currency will be unwrapped into Native currency before sending to taker
|
|
53
|
+
*/
|
|
54
|
+
isNativeUnwrapEnabled() {
|
|
55
|
+
return this.flags.getBit(TakerTraits.UNWRAP_WETH_FLAG) === 1;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Wrapped native currency will be unwrapped into Native currency before sending to taker
|
|
59
|
+
*/
|
|
60
|
+
enableNativeUnwrap() {
|
|
61
|
+
this.flags = this.flags.setBit(TakerTraits.UNWRAP_WETH_FLAG, 1);
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Wrapped native currency will NOT be unwrapped into Native currency before sending to taker
|
|
66
|
+
*/
|
|
67
|
+
disableNativeUnwrap() {
|
|
68
|
+
this.flags = this.flags.setBit(TakerTraits.UNWRAP_WETH_FLAG, 0);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* If true, then maker's permit execution is skipped
|
|
73
|
+
*/
|
|
74
|
+
isOrderPermitSkipped() {
|
|
75
|
+
return Boolean(this.flags.getBit(TakerTraits.SKIP_ORDER_PERMIT_FLAG));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The order skips maker's permit execution
|
|
79
|
+
*/
|
|
80
|
+
skipOrderPermit() {
|
|
81
|
+
this.flags = this.flags.setBit(TakerTraits.SKIP_ORDER_PERMIT_FLAG, 1);
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Should use permit2 function for authorization or not
|
|
86
|
+
*
|
|
87
|
+
* @see https://github.com/Uniswap/permit2
|
|
88
|
+
*/
|
|
89
|
+
isPermit2Enabled() {
|
|
90
|
+
return this.flags.getBit(TakerTraits.USE_PERMIT2_FLAG) === 1;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Use permit2 function for authorization
|
|
94
|
+
*
|
|
95
|
+
* @see https://github.com/Uniswap/permit2
|
|
96
|
+
*/
|
|
97
|
+
enablePermit2() {
|
|
98
|
+
this.flags = this.flags.setBit(TakerTraits.USE_PERMIT2_FLAG, 1);
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* NOT use permit2 function for authorization
|
|
103
|
+
*/
|
|
104
|
+
disablePermit2() {
|
|
105
|
+
this.flags = this.flags.setBit(TakerTraits.USE_PERMIT2_FLAG, 0);
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Sets address where order filled to, `msg.sender` used if not set
|
|
110
|
+
*
|
|
111
|
+
* @param receiver
|
|
112
|
+
*/
|
|
113
|
+
setReceiver(receiver) {
|
|
114
|
+
this.receiver = receiver;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Set order receiver as `msg.sender`
|
|
119
|
+
*/
|
|
120
|
+
removeReceiver() {
|
|
121
|
+
this.receiver = undefined;
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Sets extension, it is required to provide same extension as in order creation (if any)
|
|
126
|
+
*/
|
|
127
|
+
setExtension(ext) {
|
|
128
|
+
this.extension = ext;
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
removeExtension() {
|
|
132
|
+
this.extension = undefined;
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Set threshold amount
|
|
137
|
+
*
|
|
138
|
+
* In taker amount mode: the minimum amount a taker agrees to receive in exchange for a taking amount.
|
|
139
|
+
* In maker amount mode: the maximum amount a taker agrees to give in exchange for a making amount.
|
|
140
|
+
*
|
|
141
|
+
* @see AmountMode
|
|
142
|
+
*/
|
|
143
|
+
setAmountThreshold(threshold) {
|
|
144
|
+
this.flags = this.flags.setMask(TakerTraits.THRESHOLD_MASK, threshold);
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get threshold amount
|
|
149
|
+
*
|
|
150
|
+
* In taker amount mode: the minimum amount a taker agrees to receive in exchange for a taking amount.
|
|
151
|
+
* In maker amount mode: the maximum amount a taker agrees to give in exchange for a making amount.
|
|
152
|
+
*
|
|
153
|
+
* @see AmountMode
|
|
154
|
+
*/
|
|
155
|
+
getAmountThreshold() {
|
|
156
|
+
return this.flags.getMask(TakerTraits.THRESHOLD_MASK).value;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* @see setAmountThreshold
|
|
160
|
+
*/
|
|
161
|
+
removeAmountThreshold() {
|
|
162
|
+
this.flags = this.flags.setMask(TakerTraits.THRESHOLD_MASK, 0n);
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Sets taker interaction
|
|
167
|
+
*
|
|
168
|
+
* `interaction.target` should implement `ITakerInteraction` interface
|
|
169
|
+
*
|
|
170
|
+
* @see https://github.com/1inch/limit-order-protocol/blob/1a32e059f78ddcf1fe6294baed6cafb73a04b685/contracts/interfaces/ITakerInteraction.sol#L11
|
|
171
|
+
*/
|
|
172
|
+
setInteraction(interaction) {
|
|
173
|
+
this.interaction = interaction;
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
removeInteraction() {
|
|
177
|
+
this.interaction = undefined;
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
encode() {
|
|
181
|
+
const extensionLen = this.extension
|
|
182
|
+
? getBytesCount(this.extension.encode())
|
|
183
|
+
: 0n;
|
|
184
|
+
const interactionLen = this.interaction
|
|
185
|
+
? getBytesCount(this.interaction.encode())
|
|
186
|
+
: 0n;
|
|
187
|
+
const flags = this.flags
|
|
188
|
+
.setBit(TakerTraits.ARGS_HAS_RECEIVER, this.receiver ? 1 : 0)
|
|
189
|
+
.setMask(TakerTraits.ARGS_EXTENSION_LENGTH_MASK, extensionLen)
|
|
190
|
+
.setMask(TakerTraits.ARGS_INTERACTION_LENGTH_MASK, interactionLen);
|
|
191
|
+
const args = (this.receiver?.toString() || ZX) +
|
|
192
|
+
trim0x(this.extension?.encode() || '') +
|
|
193
|
+
trim0x(this.interaction?.encode() || '');
|
|
194
|
+
return {
|
|
195
|
+
trait: flags.value,
|
|
196
|
+
args
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
TakerTraits.MAKER_AMOUNT_FLAG = 255n;
|
|
201
|
+
TakerTraits.UNWRAP_WETH_FLAG = 254n;
|
|
202
|
+
TakerTraits.SKIP_ORDER_PERMIT_FLAG = 253n;
|
|
203
|
+
TakerTraits.USE_PERMIT2_FLAG = 252n;
|
|
204
|
+
TakerTraits.ARGS_HAS_RECEIVER = 251n;
|
|
205
|
+
TakerTraits.THRESHOLD_MASK = new BitMask(0n, 185n);
|
|
206
|
+
TakerTraits.ARGS_INTERACTION_LENGTH_MASK = new BitMask(200n, 224n);
|
|
207
|
+
TakerTraits.ARGS_EXTENSION_LENGTH_MASK = new BitMask(224n, 248n);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Extension } from './extensions/extension.js';
|
|
2
|
+
import { Address } from '../address.js';
|
|
3
|
+
export type OrderInfoData = {
|
|
4
|
+
makerAsset: Address;
|
|
5
|
+
takerAsset: Address;
|
|
6
|
+
makingAmount: bigint;
|
|
7
|
+
takingAmount: bigint;
|
|
8
|
+
maker: Address;
|
|
9
|
+
salt?: bigint;
|
|
10
|
+
receiver?: Address;
|
|
11
|
+
};
|
|
12
|
+
export type LimitOrderV4Struct = {
|
|
13
|
+
salt: string;
|
|
14
|
+
maker: string;
|
|
15
|
+
receiver: string;
|
|
16
|
+
makerAsset: string;
|
|
17
|
+
takerAsset: string;
|
|
18
|
+
makingAmount: string;
|
|
19
|
+
takingAmount: string;
|
|
20
|
+
makerTraits: string;
|
|
21
|
+
};
|
|
22
|
+
export interface IExtensionBuilder {
|
|
23
|
+
build(): Extension;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate maker traits - require:
|
|
3
|
+
* - HAS_EXTENSION_FLAG (bit 249) must be set
|
|
4
|
+
* - ALLOW_MULTIPLE_FILLS_FLAG (bit 254) must be set
|
|
5
|
+
* - NO_PARTIAL_FILLS_FLAG (bit 255) must NOT be set (partial fills must be allowed)
|
|
6
|
+
* - Nonce is required
|
|
7
|
+
* - Expiration is optional
|
|
8
|
+
* - All other flags must be unset
|
|
9
|
+
*/
|
|
10
|
+
export declare function validateMakerTraits(makerTraitsHex: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* Validate extension - for ERC6909 orders:
|
|
13
|
+
* - Sell orders (SELL_OPTIONS): makerAssetSuffix required, takerAssetSuffix must be empty
|
|
14
|
+
* - Buy orders (BUY_OPTIONS): takerAssetSuffix required, makerAssetSuffix must be empty
|
|
15
|
+
*/
|
|
16
|
+
export declare function validateExtension(extensionEncoded: string, orderType: "SELL_OPTIONS" | "BUY_OPTIONS"): void;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Extension } from "./extensions/extension";
|
|
2
|
+
/**
|
|
3
|
+
* Validate maker traits - require:
|
|
4
|
+
* - HAS_EXTENSION_FLAG (bit 249) must be set
|
|
5
|
+
* - ALLOW_MULTIPLE_FILLS_FLAG (bit 254) must be set
|
|
6
|
+
* - NO_PARTIAL_FILLS_FLAG (bit 255) must NOT be set (partial fills must be allowed)
|
|
7
|
+
* - Nonce is required
|
|
8
|
+
* - Expiration is optional
|
|
9
|
+
* - All other flags must be unset
|
|
10
|
+
*/
|
|
11
|
+
export function validateMakerTraits(makerTraitsHex) {
|
|
12
|
+
const traits = BigInt(makerTraitsHex);
|
|
13
|
+
// Bit masks for allowed features
|
|
14
|
+
const HAS_EXTENSION_FLAG = 1n << 249n;
|
|
15
|
+
const NONCE_MASK = (1n << 40n) - 1n; // bits 120-160 (40 bits)
|
|
16
|
+
const ALLOWED_SENDER_MASK = (1n << 80n) - 1n; // bits 0-80 (80 bits)
|
|
17
|
+
// Extract low 200 bits (allowed sender, expiration, nonce, series)
|
|
18
|
+
const lowBits = traits & ((1n << 200n) - 1n);
|
|
19
|
+
// Check that HAS_EXTENSION_FLAG is set (required)
|
|
20
|
+
if ((traits & HAS_EXTENSION_FLAG) === 0n) {
|
|
21
|
+
throw new Error("Invalid maker traits: HAS_EXTENSION_FLAG (bit 249) is required");
|
|
22
|
+
}
|
|
23
|
+
// Check that ALLOW_MULTIPLE_FILLS_FLAG is set (bit 254 = 1)
|
|
24
|
+
const ALLOW_MULTIPLE_FILLS_FLAG = 1n << 254n;
|
|
25
|
+
if ((traits & ALLOW_MULTIPLE_FILLS_FLAG) === 0n) {
|
|
26
|
+
throw new Error("Invalid maker traits: ALLOW_MULTIPLE_FILLS_FLAG (bit 254) must be set");
|
|
27
|
+
}
|
|
28
|
+
// Check that NO_PARTIAL_FILLS_FLAG is NOT set (bit 255 = 0)
|
|
29
|
+
const NO_PARTIAL_FILLS_FLAG = 1n << 255n;
|
|
30
|
+
if ((traits & NO_PARTIAL_FILLS_FLAG) !== 0n) {
|
|
31
|
+
throw new Error("Invalid maker traits: NO_PARTIAL_FILLS_FLAG (bit 255) must not be set (partial fills must be allowed)");
|
|
32
|
+
}
|
|
33
|
+
// Check that no other forbidden high bits are set (bits 247-253, except 249 and 254)
|
|
34
|
+
const forbiddenFlags = (1n << 253n) | // unused
|
|
35
|
+
(1n << 252n) | // PRE_INTERACTION_CALL_FLAG
|
|
36
|
+
(1n << 251n) | // POST_INTERACTION_CALL_FLAG
|
|
37
|
+
(1n << 250n) | // NEED_CHECK_EPOCH_MANAGER_FLAG
|
|
38
|
+
(1n << 248n) | // USE_PERMIT2_FLAG
|
|
39
|
+
(1n << 247n); // UNWRAP_WETH_FLAG
|
|
40
|
+
if ((traits & forbiddenFlags) !== 0n) {
|
|
41
|
+
throw new Error(`Invalid maker traits: forbidden flags detected. Only HAS_EXTENSION_FLAG (bit 249) and ALLOW_MULTIPLE_FILLS_FLAG (bit 254) are allowed in high bits`);
|
|
42
|
+
}
|
|
43
|
+
// Low 200 bits can have: allowedSender (must be 0), expiration (optional), nonce (required), series (must be 0)
|
|
44
|
+
const series = (lowBits >> 160n) & ((1n << 40n) - 1n);
|
|
45
|
+
if (series !== 0n) {
|
|
46
|
+
throw new Error("Invalid maker traits: series must be 0");
|
|
47
|
+
}
|
|
48
|
+
const nonce = (lowBits >> 120n) & NONCE_MASK;
|
|
49
|
+
if (nonce === 0n) {
|
|
50
|
+
throw new Error("Invalid maker traits: nonce is required");
|
|
51
|
+
}
|
|
52
|
+
// Expiration is optional (can be 0)
|
|
53
|
+
// Allowed sender must be 0
|
|
54
|
+
const allowedSender = lowBits & ALLOWED_SENDER_MASK;
|
|
55
|
+
if (allowedSender !== 0n) {
|
|
56
|
+
throw new Error("Invalid maker traits: allowedSender must be 0");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Validate extension - for ERC6909 orders:
|
|
61
|
+
* - Sell orders (SELL_OPTIONS): makerAssetSuffix required, takerAssetSuffix must be empty
|
|
62
|
+
* - Buy orders (BUY_OPTIONS): takerAssetSuffix required, makerAssetSuffix must be empty
|
|
63
|
+
*/
|
|
64
|
+
export function validateExtension(extensionEncoded, orderType) {
|
|
65
|
+
const extension = Extension.decode(extensionEncoded);
|
|
66
|
+
// Check that forbidden fields are empty
|
|
67
|
+
if (extension.makingAmountData !== "0x") {
|
|
68
|
+
throw new Error("Invalid extension: makingAmountData must be empty");
|
|
69
|
+
}
|
|
70
|
+
if (extension.takingAmountData !== "0x") {
|
|
71
|
+
throw new Error("Invalid extension: takingAmountData must be empty");
|
|
72
|
+
}
|
|
73
|
+
if (extension.predicate !== "0x") {
|
|
74
|
+
throw new Error("Invalid extension: predicate must be empty");
|
|
75
|
+
}
|
|
76
|
+
if (extension.makerPermit !== "0x") {
|
|
77
|
+
throw new Error("Invalid extension: makerPermit must be empty");
|
|
78
|
+
}
|
|
79
|
+
if (extension.preInteraction !== "0x") {
|
|
80
|
+
throw new Error("Invalid extension: preInteraction must be empty");
|
|
81
|
+
}
|
|
82
|
+
if (extension.postInteraction !== "0x") {
|
|
83
|
+
throw new Error("Invalid extension: postInteraction must be empty");
|
|
84
|
+
}
|
|
85
|
+
if (extension.customData !== "0x") {
|
|
86
|
+
throw new Error("Invalid extension: customData must be empty");
|
|
87
|
+
}
|
|
88
|
+
const hasMakerSuffix = extension.makerAssetSuffix !== "0x";
|
|
89
|
+
const hasTakerSuffix = extension.takerAssetSuffix !== "0x";
|
|
90
|
+
if (orderType === "SELL_OPTIONS") {
|
|
91
|
+
// Sell: maker gives options, so makerAssetSuffix required
|
|
92
|
+
if (!hasMakerSuffix) {
|
|
93
|
+
throw new Error("Invalid extension for SELL_OPTIONS: makerAssetSuffix is required");
|
|
94
|
+
}
|
|
95
|
+
if (hasTakerSuffix) {
|
|
96
|
+
throw new Error("Invalid extension for SELL_OPTIONS: takerAssetSuffix must be empty");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// Buy: taker gives options, so takerAssetSuffix required
|
|
101
|
+
if (!hasTakerSuffix) {
|
|
102
|
+
throw new Error("Invalid extension for BUY_OPTIONS: takerAssetSuffix is required");
|
|
103
|
+
}
|
|
104
|
+
if (hasMakerSuffix) {
|
|
105
|
+
throw new Error("Invalid extension for BUY_OPTIONS: makerAssetSuffix must be empty");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { LimitOrderV4Struct, TakerTraits } from '../limit-order/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* @see https://github.com/1inch/limit-order-protocol/blob/3169ea46932ef44114a215a60d1d91ef022b416d/contracts/OrderMixin.sol#L27
|
|
4
|
+
*/
|
|
5
|
+
export declare class LimitOrderContract {
|
|
6
|
+
/**
|
|
7
|
+
* Fill order WITHOUT an extension and taker interaction
|
|
8
|
+
*
|
|
9
|
+
* @see getFillOrderArgsCalldata
|
|
10
|
+
* @see getFillContractOrderCalldata
|
|
11
|
+
*/
|
|
12
|
+
static getFillOrderCalldata(order: LimitOrderV4Struct, signature: string, takerTraits: TakerTraits, amount: bigint): string;
|
|
13
|
+
/**
|
|
14
|
+
* Fill contract order (order maker is smart-contract) WITHOUT an extension and taker interaction
|
|
15
|
+
*
|
|
16
|
+
* @see getFillContractOrderArgsCalldata
|
|
17
|
+
* @see getFillOrderCalldata
|
|
18
|
+
*/
|
|
19
|
+
static getFillContractOrderCalldata(order: LimitOrderV4Struct, signature: string, takerTraits: TakerTraits, amount: bigint): string;
|
|
20
|
+
/**
|
|
21
|
+
* Fill order WITH an extension or taker interaction
|
|
22
|
+
*
|
|
23
|
+
* @see getFillOrderCalldata
|
|
24
|
+
* @see getFillContractOrderArgsCalldata
|
|
25
|
+
*/
|
|
26
|
+
static getFillOrderArgsCalldata(order: LimitOrderV4Struct, signature: string, takerTraits: TakerTraits, amount: bigint): string;
|
|
27
|
+
/**
|
|
28
|
+
* Fill contract order (order maker is smart-contract) WITH an extension or taker interaction
|
|
29
|
+
*
|
|
30
|
+
* @see getFillOrderArgsCalldata
|
|
31
|
+
* @see getFillContractOrderCalldata
|
|
32
|
+
*/
|
|
33
|
+
static getFillContractOrderArgsCalldata(order: LimitOrderV4Struct, signature: string, takerTraits: TakerTraits, amount: bigint): string;
|
|
34
|
+
}
|