@1inch/fusion-sdk 0.0.6 → 0.0.8
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 +4 -0
- package/api/fusion-api.d.ts +16 -25
- package/api/fusion-api.js +26 -36
- package/api/index.d.ts +4 -4
- package/api/index.js +8 -8
- package/api/orders/index.d.ts +3 -3
- package/api/orders/index.js +7 -7
- package/api/orders/order-api.spec.d.ts +1 -1
- package/api/orders/order-api.spec.js +397 -479
- package/api/orders/orders.api.d.ts +10 -24
- package/api/orders/orders.api.js +28 -30
- package/api/orders/orders.request.d.ts +18 -22
- package/api/orders/orders.request.js +31 -40
- package/api/orders/types.d.ts +58 -59
- package/api/orders/types.js +16 -17
- package/api/pagination.d.ts +7 -7
- package/api/pagination.js +10 -10
- package/api/pagination.spec.d.ts +1 -1
- package/api/pagination.spec.js +21 -28
- package/api/params.d.ts +1 -3
- package/api/params.js +19 -25
- package/api/quoter/index.d.ts +5 -5
- package/api/quoter/index.js +9 -9
- package/api/quoter/preset.d.ts +13 -13
- package/api/quoter/preset.js +17 -19
- package/api/quoter/quote/index.d.ts +3 -3
- package/api/quoter/quote/index.js +7 -7
- package/api/quoter/quote/order-params.d.ts +7 -6
- package/api/quoter/quote/order-params.js +13 -12
- package/api/quoter/quote/order-params.js.map +1 -1
- package/api/quoter/quote/quote.d.ts +22 -26
- package/api/quoter/quote/quote.js +59 -84
- package/api/quoter/quote/quote.js.map +1 -1
- package/api/quoter/quote/types.d.ts +5 -4
- package/api/quoter/quote/types.js +3 -3
- package/api/quoter/quoter.api.d.ts +9 -12
- package/api/quoter/quoter.api.js +19 -19
- package/api/quoter/quoter.api.spec.d.ts +1 -1
- package/api/quoter/quoter.api.spec.js +24 -30
- package/api/quoter/quoter.api.spec.js.map +1 -1
- package/api/quoter/quoter.request.d.ts +11 -11
- package/api/quoter/quoter.request.js +26 -28
- package/api/quoter/types.d.ts +45 -45
- package/api/quoter/types.js +10 -10
- package/api/relayer/index.d.ts +3 -3
- package/api/relayer/index.js +7 -7
- package/api/relayer/relayer.api.d.ts +9 -12
- package/api/relayer/relayer.api.js +13 -13
- package/api/relayer/relayer.api.spec.d.ts +1 -1
- package/api/relayer/relayer.api.spec.js +79 -96
- package/api/relayer/relayer.request.d.ts +8 -8
- package/api/relayer/relayer.request.js +10 -10
- package/api/relayer/types.d.ts +9 -9
- package/api/relayer/types.js +3 -3
- package/api/types.d.ts +15 -17
- package/api/types.js +3 -3
- package/auction-calculator/auction-calculator.d.ts +13 -22
- package/auction-calculator/auction-calculator.js +45 -70
- package/auction-calculator/auction-calculator.spec.d.ts +1 -1
- package/auction-calculator/auction-calculator.spec.js +32 -45
- package/auction-calculator/calc.d.ts +2 -8
- package/auction-calculator/calc.js +12 -12
- package/auction-calculator/constants.d.ts +1 -1
- package/auction-calculator/constants.js +5 -5
- package/auction-calculator/index.d.ts +3 -3
- package/auction-calculator/index.js +7 -7
- package/auction-salt/auction-salt.d.ts +9 -9
- package/auction-salt/auction-salt.js +23 -34
- package/auction-salt/auction.salt.spec.d.ts +1 -1
- package/auction-salt/auction.salt.spec.js +27 -38
- package/auction-salt/index.d.ts +3 -3
- package/auction-salt/index.js +7 -7
- package/auction-salt/parser/constants.d.ts +9 -9
- package/auction-salt/parser/constants.js +14 -33
- package/auction-salt/parser/index.d.ts +2 -2
- package/auction-salt/parser/index.js +6 -6
- package/auction-salt/parser/parser.d.ts +6 -6
- package/auction-salt/parser/parser.js +22 -33
- package/auction-salt/types.d.ts +6 -6
- package/auction-salt/types.js +3 -3
- package/auction-suffix/auction-suffix.d.ts +9 -9
- package/auction-suffix/auction-suffix.js +23 -36
- package/auction-suffix/auction-suffix.spec.d.ts +1 -1
- package/auction-suffix/auction-suffix.spec.js +15 -20
- package/auction-suffix/constants.d.ts +1 -1
- package/auction-suffix/constants.js +5 -5
- package/auction-suffix/encoder.d.ts +6 -15
- package/auction-suffix/encoder.js +28 -45
- package/auction-suffix/index.d.ts +5 -5
- package/auction-suffix/index.js +9 -9
- package/auction-suffix/parser/constants.d.ts +13 -13
- package/auction-suffix/parser/constants.js +17 -30
- package/auction-suffix/parser/errors.d.ts +2 -1
- package/auction-suffix/parser/errors.js +7 -6
- package/auction-suffix/parser/index.d.ts +4 -4
- package/auction-suffix/parser/index.js +8 -8
- package/auction-suffix/parser/parser.d.ts +8 -28
- package/auction-suffix/parser/parser.js +81 -162
- package/auction-suffix/parser/types.d.ts +22 -22
- package/auction-suffix/parser/types.js +3 -3
- package/auction-suffix/types.d.ts +12 -12
- package/auction-suffix/types.js +3 -3
- package/connector/blockchain/blockchain-provider.connector.d.ts +3 -6
- package/connector/blockchain/blockchain-provider.connector.js +3 -3
- package/connector/blockchain/index.d.ts +3 -3
- package/connector/blockchain/index.js +7 -7
- package/connector/blockchain/private-key-provider.connector.d.ts +10 -15
- package/connector/blockchain/private-key-provider.connector.js +12 -12
- package/connector/blockchain/private-key-provider.connector.spec.d.ts +1 -1
- package/connector/blockchain/private-key-provider.connector.spec.js +23 -36
- package/connector/blockchain/web3-provider-connector.d.ts +8 -13
- package/connector/blockchain/web3-provider-connector.js +9 -12
- package/connector/blockchain/web3-provider.connector.spec.d.ts +1 -1
- package/connector/blockchain/web3-provider.connector.spec.js +26 -37
- package/connector/http/axios-provider.connector.d.ts +3 -3
- package/connector/http/axios-provider.connector.js +13 -13
- package/connector/http/axios-provider.connector.spec.d.ts +1 -1
- package/connector/http/axios-provider.connector.spec.js +31 -37
- package/connector/http/http-provider.connector.d.ts +2 -2
- package/connector/http/http-provider.connector.js +3 -3
- package/connector/http/index.d.ts +2 -2
- package/connector/http/index.js +6 -6
- package/connector/index.d.ts +2 -2
- package/connector/index.js +6 -6
- package/constants.d.ts +6 -10
- package/constants.js +16 -23
- package/fusion-order/fusion-order.d.ts +7 -17
- package/fusion-order/fusion-order.js +12 -14
- package/fusion-order/fusion-order.spec.d.ts +1 -1
- package/fusion-order/fusion-order.spec.js +22 -27
- package/fusion-order/index.d.ts +1 -1
- package/fusion-order/index.js +5 -5
- package/index.d.ts +11 -11
- package/index.js +15 -15
- package/limit-order/eip712/domain.d.ts +9 -10
- package/limit-order/eip712/domain.js +23 -28
- package/limit-order/eip712/eip712.types.d.ts +15 -19
- package/limit-order/eip712/eip712.types.js +3 -3
- package/limit-order/eip712/index.d.ts +3 -3
- package/limit-order/eip712/index.js +7 -7
- package/limit-order/eip712/order-typed-data-builder.d.ts +6 -17
- package/limit-order/eip712/order-typed-data-builder.js +19 -34
- package/limit-order/index.d.ts +4 -4
- package/limit-order/index.js +8 -8
- package/limit-order/interactions-factory.d.ts +1 -1
- package/limit-order/interactions-factory.js +6 -6
- package/limit-order/limit-order.d.ts +25 -31
- package/limit-order/limit-order.js +50 -103
- package/limit-order/limit-order.spec.d.ts +1 -1
- package/limit-order/limit-order.spec.js +51 -75
- package/limit-order/parser/constants.d.ts +9 -9
- package/limit-order/parser/constants.js +5 -5
- package/limit-order/parser/index.d.ts +3 -3
- package/limit-order/parser/index.js +7 -7
- package/limit-order/parser/parser.d.ts +2 -5
- package/limit-order/parser/parser.js +18 -23
- package/limit-order/parser/types.d.ts +3 -3
- package/limit-order/parser/types.js +3 -3
- package/limit-order/predicate-factory.d.ts +5 -9
- package/limit-order/predicate-factory.js +24 -40
- package/limit-order/predicate-factory.spec.d.ts +1 -1
- package/limit-order/predicate-factory.spec.js +29 -44
- package/limit-order/types.d.ts +29 -29
- package/limit-order/types.js +3 -3
- package/limit-order/utils.d.ts +1 -1
- package/limit-order/utils.js +6 -6
- package/package.json +1 -1
- package/sdk/index.d.ts +2 -2
- package/sdk/index.js +6 -6
- package/sdk/sdk.d.ts +11 -29
- package/sdk/sdk.js +40 -49
- package/sdk/sdk.js.map +1 -1
- package/sdk/types.d.ts +27 -27
- package/sdk/types.js +3 -3
- package/settlement/encoders/constants.d.ts +1 -1
- package/settlement/encoders/constants.js +5 -5
- package/settlement/encoders/fill-order.encoder.d.ts +2 -2
- package/settlement/encoders/fill-order.encoder.js +12 -26
- package/settlement/encoders/index.d.ts +3 -3
- package/settlement/encoders/index.js +7 -7
- package/settlement/encoders/settlement.encoder.d.ts +5 -13
- package/settlement/encoders/settlement.encoder.js +38 -42
- package/settlement/encoders/settlement.encoder.js.map +1 -1
- package/settlement/index.d.ts +4 -4
- package/settlement/index.js +8 -8
- package/settlement/settlement.d.ts +6 -8
- package/settlement/settlement.js +20 -28
- package/settlement/settlement.js.map +1 -1
- package/settlement/settlement.spec.d.ts +1 -1
- package/settlement/settlement.spec.js +41 -45
- package/settlement/settlement.spec.js.map +1 -1
- package/settlement/signature-patcher.d.ts +1 -1
- package/settlement/signature-patcher.js +16 -19
- package/settlement/types.d.ts +13 -13
- package/settlement/types.js +3 -3
- package/utils.d.ts +6 -6
- package/utils.js +23 -29
- package/validations.d.ts +2 -2
- package/validations.js +15 -14
|
@@ -1,28 +1,19 @@
|
|
|
1
|
-
import {AuctionPoint, AuctionSuffix} from '../auction-suffix'
|
|
2
|
-
import {LimitOrderV3Struct} from '../limit-order'
|
|
3
|
-
import {AuctionSalt} from '../auction-salt'
|
|
1
|
+
import { AuctionPoint, AuctionSuffix } from '../auction-suffix';
|
|
2
|
+
import { LimitOrderV3Struct } from '../limit-order';
|
|
3
|
+
import { AuctionSalt } from '../auction-salt';
|
|
4
4
|
export declare class AuctionCalculator {
|
|
5
|
-
private readonly startTime
|
|
6
|
-
private readonly duration
|
|
7
|
-
private readonly initialRateBump
|
|
8
|
-
private readonly points
|
|
9
|
-
private readonly takerFeeRatio
|
|
10
|
-
constructor(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
points: AuctionPoint[],
|
|
15
|
-
takerFeeRatio: string
|
|
16
|
-
)
|
|
17
|
-
static fromLimitOrderV3Struct(order: LimitOrderV3Struct): AuctionCalculator
|
|
18
|
-
static fromAuctionData(
|
|
19
|
-
suffix: AuctionSuffix,
|
|
20
|
-
salt: AuctionSalt
|
|
21
|
-
): AuctionCalculator
|
|
22
|
-
calcAuctionTakingAmount(takingAmount: string, rate: number): string
|
|
5
|
+
private readonly startTime;
|
|
6
|
+
private readonly duration;
|
|
7
|
+
private readonly initialRateBump;
|
|
8
|
+
private readonly points;
|
|
9
|
+
private readonly takerFeeRatio;
|
|
10
|
+
constructor(startTime: number, duration: number, initialRateBump: number, points: AuctionPoint[], takerFeeRatio: string);
|
|
11
|
+
static fromLimitOrderV3Struct(order: LimitOrderV3Struct): AuctionCalculator;
|
|
12
|
+
static fromAuctionData(suffix: AuctionSuffix, salt: AuctionSalt): AuctionCalculator;
|
|
13
|
+
calcAuctionTakingAmount(takingAmount: string, rate: number): string;
|
|
23
14
|
/**
|
|
24
15
|
* @see https://github.com/1inch/limit-order-settlement/blob/3c7cf9eacbaf7a60624d7a6f069c59d809f2204a/contracts/libraries/OrderSuffix.sol#L75
|
|
25
16
|
* @param time auction timestamp in seconds
|
|
26
17
|
*/
|
|
27
|
-
calcRateBump(time: number): number
|
|
18
|
+
calcRateBump(time: number): number;
|
|
28
19
|
}
|
|
@@ -1,96 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.AuctionCalculator = void 0
|
|
4
|
-
const auction_suffix_1 = require(
|
|
5
|
-
const auction_salt_1 = require(
|
|
6
|
-
const bignumber_1 = require(
|
|
7
|
-
const calc_1 = require(
|
|
8
|
-
const constants_1 = require(
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuctionCalculator = void 0;
|
|
4
|
+
const auction_suffix_1 = require("../auction-suffix");
|
|
5
|
+
const auction_salt_1 = require("../auction-salt");
|
|
6
|
+
const bignumber_1 = require("@ethersproject/bignumber");
|
|
7
|
+
const calc_1 = require("./calc");
|
|
8
|
+
const constants_1 = require("./constants");
|
|
9
9
|
class AuctionCalculator {
|
|
10
10
|
constructor(startTime, duration, initialRateBump, points, takerFeeRatio) {
|
|
11
|
-
this.startTime = startTime
|
|
12
|
-
this.duration = duration
|
|
13
|
-
this.initialRateBump = initialRateBump
|
|
14
|
-
this.points = points
|
|
15
|
-
this.takerFeeRatio = takerFeeRatio
|
|
11
|
+
this.startTime = startTime;
|
|
12
|
+
this.duration = duration;
|
|
13
|
+
this.initialRateBump = initialRateBump;
|
|
14
|
+
this.points = points;
|
|
15
|
+
this.takerFeeRatio = takerFeeRatio;
|
|
16
16
|
}
|
|
17
17
|
static fromLimitOrderV3Struct(order) {
|
|
18
|
-
const suffix = auction_suffix_1.AuctionSuffix.decode(order.interactions)
|
|
19
|
-
const salt = auction_salt_1.AuctionSalt.decode(order.salt)
|
|
20
|
-
return AuctionCalculator.fromAuctionData(suffix, salt)
|
|
18
|
+
const suffix = auction_suffix_1.AuctionSuffix.decode(order.interactions);
|
|
19
|
+
const salt = auction_salt_1.AuctionSalt.decode(order.salt);
|
|
20
|
+
return AuctionCalculator.fromAuctionData(suffix, salt);
|
|
21
21
|
}
|
|
22
22
|
static fromAuctionData(suffix, salt) {
|
|
23
|
-
return new AuctionCalculator(
|
|
24
|
-
salt.auctionStartTime,
|
|
25
|
-
salt.duration,
|
|
26
|
-
salt.initialRateBump,
|
|
27
|
-
suffix.points,
|
|
28
|
-
suffix.takerFeeRatio
|
|
29
|
-
)
|
|
23
|
+
return new AuctionCalculator(salt.auctionStartTime, salt.duration, salt.initialRateBump, suffix.points, suffix.takerFeeRatio);
|
|
30
24
|
}
|
|
31
25
|
calcAuctionTakingAmount(takingAmount, rate) {
|
|
32
26
|
const auctionTakingAmount = bignumber_1.BigNumber.from(takingAmount)
|
|
33
|
-
.mul(
|
|
34
|
-
|
|
35
|
-
constants_1.RATE_BUMP_DENOMINATOR
|
|
36
|
-
)
|
|
37
|
-
)
|
|
38
|
-
.div(constants_1.RATE_BUMP_DENOMINATOR)
|
|
27
|
+
.mul(bignumber_1.BigNumber.from(rate).add(constants_1.RATE_BUMP_DENOMINATOR))
|
|
28
|
+
.div(constants_1.RATE_BUMP_DENOMINATOR);
|
|
39
29
|
if (this.takerFeeRatio === '0') {
|
|
40
|
-
return auctionTakingAmount.toString()
|
|
30
|
+
return auctionTakingAmount.toString();
|
|
41
31
|
}
|
|
42
32
|
return auctionTakingAmount
|
|
43
|
-
.add(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
48
|
-
.toString()
|
|
33
|
+
.add(auctionTakingAmount
|
|
34
|
+
.mul(this.takerFeeRatio)
|
|
35
|
+
.div(auction_suffix_1.CONTRACT_TAKER_FEE_PRECISION))
|
|
36
|
+
.toString();
|
|
49
37
|
}
|
|
50
38
|
/**
|
|
51
39
|
* @see https://github.com/1inch/limit-order-settlement/blob/3c7cf9eacbaf7a60624d7a6f069c59d809f2204a/contracts/libraries/OrderSuffix.sol#L75
|
|
52
40
|
* @param time auction timestamp in seconds
|
|
53
41
|
*/
|
|
54
42
|
calcRateBump(time) {
|
|
55
|
-
let cumulativeTime = bignumber_1.BigNumber.from(this.startTime)
|
|
56
|
-
const lastTime = bignumber_1.BigNumber.from(this.duration).add(
|
|
57
|
-
|
|
58
|
-
)
|
|
59
|
-
const startBump = bignumber_1.BigNumber.from(this.initialRateBump)
|
|
60
|
-
const currentTime = bignumber_1.BigNumber.from(time)
|
|
43
|
+
let cumulativeTime = bignumber_1.BigNumber.from(this.startTime);
|
|
44
|
+
const lastTime = bignumber_1.BigNumber.from(this.duration).add(cumulativeTime);
|
|
45
|
+
const startBump = bignumber_1.BigNumber.from(this.initialRateBump);
|
|
46
|
+
const currentTime = bignumber_1.BigNumber.from(time);
|
|
61
47
|
if (currentTime.lte(cumulativeTime)) {
|
|
62
|
-
return this.initialRateBump
|
|
63
|
-
} else if (currentTime.gte(lastTime)) {
|
|
64
|
-
return 0
|
|
48
|
+
return this.initialRateBump;
|
|
65
49
|
}
|
|
66
|
-
|
|
67
|
-
|
|
50
|
+
else if (currentTime.gte(lastTime)) {
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
let prevCoefficient = startBump;
|
|
54
|
+
let prevCumulativeTime = cumulativeTime;
|
|
68
55
|
for (let i = this.points.length - 1; i >= 0; i--) {
|
|
69
|
-
const {coefficient, delay} = this.points[i]
|
|
70
|
-
cumulativeTime = cumulativeTime.add(delay)
|
|
71
|
-
const coefficientBN = bignumber_1.BigNumber.from(coefficient)
|
|
56
|
+
const { coefficient, delay } = this.points[i];
|
|
57
|
+
cumulativeTime = cumulativeTime.add(delay);
|
|
58
|
+
const coefficientBN = bignumber_1.BigNumber.from(coefficient);
|
|
72
59
|
if (cumulativeTime.gt(currentTime)) {
|
|
73
|
-
const rate = (0, calc_1.linearInterpolation)(
|
|
74
|
-
|
|
75
|
-
cumulativeTime,
|
|
76
|
-
prevCoefficient,
|
|
77
|
-
coefficientBN,
|
|
78
|
-
currentTime
|
|
79
|
-
)
|
|
80
|
-
return rate.toNumber()
|
|
60
|
+
const rate = (0, calc_1.linearInterpolation)(prevCumulativeTime, cumulativeTime, prevCoefficient, coefficientBN, currentTime);
|
|
61
|
+
return rate.toNumber();
|
|
81
62
|
}
|
|
82
|
-
prevCumulativeTime = cumulativeTime
|
|
83
|
-
prevCoefficient = coefficientBN
|
|
63
|
+
prevCumulativeTime = cumulativeTime;
|
|
64
|
+
prevCoefficient = coefficientBN;
|
|
84
65
|
}
|
|
85
|
-
const rate = (0, calc_1.linearInterpolation)(
|
|
86
|
-
|
|
87
|
-
lastTime,
|
|
88
|
-
prevCoefficient,
|
|
89
|
-
bignumber_1.BigNumber.from(0),
|
|
90
|
-
currentTime
|
|
91
|
-
)
|
|
92
|
-
return rate.toNumber()
|
|
66
|
+
const rate = (0, calc_1.linearInterpolation)(prevCumulativeTime, lastTime, prevCoefficient, bignumber_1.BigNumber.from(0), currentTime);
|
|
67
|
+
return rate.toNumber();
|
|
93
68
|
}
|
|
94
69
|
}
|
|
95
|
-
exports.AuctionCalculator = AuctionCalculator
|
|
96
|
-
//# sourceMappingURL=auction-calculator.js.map
|
|
70
|
+
exports.AuctionCalculator = AuctionCalculator;
|
|
71
|
+
//# sourceMappingURL=auction-calculator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {}
|
|
1
|
+
export {};
|
|
@@ -1,48 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
const auction_suffix_1 = require(
|
|
4
|
-
const auction_salt_1 = require(
|
|
5
|
-
const auction_calculator_1 = require(
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const auction_suffix_1 = require("../auction-suffix");
|
|
4
|
+
const auction_salt_1 = require("../auction-salt");
|
|
5
|
+
const auction_calculator_1 = require("./auction-calculator");
|
|
6
6
|
describe('Auction Calculator', () => {
|
|
7
7
|
it('should calculate auction rate and taking amount', () => {
|
|
8
|
-
const calculator =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
rate
|
|
26
|
-
)
|
|
27
|
-
expect(rate).toBe(14285)
|
|
28
|
-
expect(auctionTakingAmount).toBe('1422028470')
|
|
29
|
-
})
|
|
8
|
+
const calculator = auction_calculator_1.AuctionCalculator.fromLimitOrderV3Struct({
|
|
9
|
+
allowedSender: '0x0000000000000000000000000000000000000000',
|
|
10
|
+
interactions: '0x000c004e200000000000000000219ab540356cbb839cbe05303d7705faf486570009',
|
|
11
|
+
maker: '0x00000000219ab540356cbb839cbe05303d7705fa',
|
|
12
|
+
makerAsset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
13
|
+
makingAmount: '1000000000000000000',
|
|
14
|
+
offsets: '0',
|
|
15
|
+
receiver: '0x0000000000000000000000000000000000000000',
|
|
16
|
+
salt: '45118768841948961586167738353692277076075522015101619148498725069326976558864',
|
|
17
|
+
takerAsset: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
18
|
+
takingAmount: '1420000000'
|
|
19
|
+
});
|
|
20
|
+
const rate = calculator.calcRateBump(1673548209);
|
|
21
|
+
const auctionTakingAmount = calculator.calcAuctionTakingAmount('1420000000', rate);
|
|
22
|
+
expect(rate).toBe(14285);
|
|
23
|
+
expect(auctionTakingAmount).toBe('1422028470');
|
|
24
|
+
});
|
|
30
25
|
it('should be created successfully from suffix and salt', () => {
|
|
31
|
-
const suffix = auction_suffix_1.AuctionSuffix.decode(
|
|
32
|
-
|
|
33
|
-
)
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
'1420000000',
|
|
42
|
-
rate
|
|
43
|
-
)
|
|
44
|
-
expect(rate).toBe(14285)
|
|
45
|
-
expect(auctionTakingAmount).toBe('1422028470')
|
|
46
|
-
})
|
|
47
|
-
})
|
|
48
|
-
//# sourceMappingURL=auction-calculator.spec.js.map
|
|
26
|
+
const suffix = auction_suffix_1.AuctionSuffix.decode('0x000c004e200000000000000000219ab540356cbb839cbe05303d7705faf486570009');
|
|
27
|
+
const salt = auction_salt_1.AuctionSalt.decode('45118768841948961586167738353692277076075522015101619148498725069326976558864');
|
|
28
|
+
const calculator = auction_calculator_1.AuctionCalculator.fromAuctionData(suffix, salt);
|
|
29
|
+
const rate = calculator.calcRateBump(1673548209);
|
|
30
|
+
const auctionTakingAmount = calculator.calcAuctionTakingAmount('1420000000', rate);
|
|
31
|
+
expect(rate).toBe(14285);
|
|
32
|
+
expect(auctionTakingAmount).toBe('1422028470');
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=auction-calculator.spec.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {BigNumber} from '@ethersproject/bignumber'
|
|
1
|
+
import { BigNumber } from '@ethersproject/bignumber';
|
|
2
2
|
/**
|
|
3
3
|
*
|
|
4
4
|
* v2(t-t1) + v1(t2-t)
|
|
@@ -7,10 +7,4 @@ import {BigNumber} from '@ethersproject/bignumber'
|
|
|
7
7
|
*
|
|
8
8
|
* @see https://github.com/1inch/limit-order-settlement/blob/3c7cf9eacbaf7a60624d7a6f069c59d809f2204a/contracts/libraries/OrderSuffix.sol#L94
|
|
9
9
|
*/
|
|
10
|
-
export declare function linearInterpolation(
|
|
11
|
-
t1: BigNumber,
|
|
12
|
-
t2: BigNumber,
|
|
13
|
-
v1: BigNumber,
|
|
14
|
-
v2: BigNumber,
|
|
15
|
-
t: BigNumber
|
|
16
|
-
): BigNumber
|
|
10
|
+
export declare function linearInterpolation(t1: BigNumber, t2: BigNumber, v1: BigNumber, v2: BigNumber, t: BigNumber): BigNumber;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.linearInterpolation = void 0
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.linearInterpolation = void 0;
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
6
6
|
* v2(t-t1) + v1(t2-t)
|
|
@@ -10,13 +10,13 @@ exports.linearInterpolation = void 0
|
|
|
10
10
|
* @see https://github.com/1inch/limit-order-settlement/blob/3c7cf9eacbaf7a60624d7a6f069c59d809f2204a/contracts/libraries/OrderSuffix.sol#L94
|
|
11
11
|
*/
|
|
12
12
|
function linearInterpolation(t1, t2, v1, v2, t) {
|
|
13
|
-
const timePassedFromNow = t.sub(t1)
|
|
14
|
-
const timeLeft = t2.sub(t)
|
|
15
|
-
const partialCoefficient = v2.mul(timePassedFromNow)
|
|
16
|
-
const partialPrevCoefficient = v1.mul(timeLeft)
|
|
17
|
-
const coefficient = partialCoefficient.add(partialPrevCoefficient)
|
|
18
|
-
const pointsTimeDiff = t2.sub(t1)
|
|
19
|
-
return coefficient.div(pointsTimeDiff)
|
|
13
|
+
const timePassedFromNow = t.sub(t1);
|
|
14
|
+
const timeLeft = t2.sub(t);
|
|
15
|
+
const partialCoefficient = v2.mul(timePassedFromNow);
|
|
16
|
+
const partialPrevCoefficient = v1.mul(timeLeft);
|
|
17
|
+
const coefficient = partialCoefficient.add(partialPrevCoefficient);
|
|
18
|
+
const pointsTimeDiff = t2.sub(t1);
|
|
19
|
+
return coefficient.div(pointsTimeDiff);
|
|
20
20
|
}
|
|
21
|
-
exports.linearInterpolation = linearInterpolation
|
|
22
|
-
//# sourceMappingURL=calc.js.map
|
|
21
|
+
exports.linearInterpolation = linearInterpolation;
|
|
22
|
+
//# sourceMappingURL=calc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const RATE_BUMP_DENOMINATOR = 10000000
|
|
1
|
+
export declare const RATE_BUMP_DENOMINATOR = 10000000;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.RATE_BUMP_DENOMINATOR = void 0
|
|
4
|
-
exports.RATE_BUMP_DENOMINATOR = 10000000 // 100%
|
|
5
|
-
//# sourceMappingURL=constants.js.map
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RATE_BUMP_DENOMINATOR = void 0;
|
|
4
|
+
exports.RATE_BUMP_DENOMINATOR = 10000000; // 100%
|
|
5
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './auction-calculator'
|
|
2
|
-
export * from './calc'
|
|
3
|
-
export * from './constants'
|
|
1
|
+
export * from './auction-calculator';
|
|
2
|
+
export * from './calc';
|
|
3
|
+
export * from './constants';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
const tslib_1 = require(
|
|
4
|
-
tslib_1.__exportStar(require(
|
|
5
|
-
tslib_1.__exportStar(require(
|
|
6
|
-
tslib_1.__exportStar(require(
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./auction-calculator"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./calc"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./constants"), exports);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {AuctionSaltData} from './types'
|
|
1
|
+
import { AuctionSaltData } from './types';
|
|
2
2
|
export declare class AuctionSalt {
|
|
3
|
-
readonly auctionStartTime: number
|
|
4
|
-
readonly initialRateBump: number
|
|
5
|
-
readonly duration: number
|
|
6
|
-
readonly bankFee: string
|
|
7
|
-
readonly salt: string
|
|
8
|
-
constructor(auction: AuctionSaltData)
|
|
9
|
-
static decode(salt: string): AuctionSalt
|
|
10
|
-
build(): string
|
|
3
|
+
readonly auctionStartTime: number;
|
|
4
|
+
readonly initialRateBump: number;
|
|
5
|
+
readonly duration: number;
|
|
6
|
+
readonly bankFee: string;
|
|
7
|
+
readonly salt: string;
|
|
8
|
+
constructor(auction: AuctionSaltData);
|
|
9
|
+
static decode(salt: string): AuctionSalt;
|
|
10
|
+
build(): string;
|
|
11
11
|
}
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.AuctionSalt = void 0
|
|
4
|
-
const tslib_1 = require(
|
|
5
|
-
const assert_1 = tslib_1.__importDefault(require(
|
|
6
|
-
const utils_1 = require(
|
|
7
|
-
const crypto_1 = require(
|
|
8
|
-
const parser_1 = require(
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuctionSalt = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const crypto_1 = require("crypto");
|
|
8
|
+
const parser_1 = require("./parser");
|
|
9
9
|
class AuctionSalt {
|
|
10
10
|
constructor(auction) {
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
parser_1.SALT_MASK.lt((0, utils_1.toBN)(auction.salt))
|
|
14
|
-
) {
|
|
15
|
-
throw new Error('salt should be less 18 bytes')
|
|
11
|
+
if (auction.salt && parser_1.SALT_MASK.lt((0, utils_1.toBN)(auction.salt))) {
|
|
12
|
+
throw new Error('salt should be less 18 bytes');
|
|
16
13
|
}
|
|
17
|
-
this.salt = auction.salt || (0, crypto_1.randomInt)(10000).toString()
|
|
18
|
-
this.auctionStartTime = auction.auctionStartTime
|
|
19
|
-
this.initialRateBump = auction.initialRateBump
|
|
20
|
-
this.duration = auction.duration
|
|
21
|
-
this.bankFee = auction.bankFee
|
|
14
|
+
this.salt = auction.salt || (0, crypto_1.randomInt)(10000).toString();
|
|
15
|
+
this.auctionStartTime = auction.auctionStartTime;
|
|
16
|
+
this.initialRateBump = auction.initialRateBump;
|
|
17
|
+
this.duration = auction.duration;
|
|
18
|
+
this.bankFee = auction.bankFee;
|
|
22
19
|
}
|
|
23
20
|
static decode(salt) {
|
|
24
21
|
return new AuctionSalt({
|
|
@@ -27,25 +24,17 @@ class AuctionSalt {
|
|
|
27
24
|
duration: (0, parser_1.getDuration)(salt).toNumber(),
|
|
28
25
|
bankFee: (0, parser_1.getFee)(salt).toString(),
|
|
29
26
|
initialRateBump: (0, parser_1.getInitialRateBump)(salt).toNumber()
|
|
30
|
-
})
|
|
27
|
+
});
|
|
31
28
|
}
|
|
32
29
|
build() {
|
|
33
|
-
const res =
|
|
34
|
-
(0, utils_1.toBN)(this.auctionStartTime)
|
|
35
|
-
.toString('hex')
|
|
36
|
-
.padStart(8, '0') +
|
|
30
|
+
const res = (0, utils_1.toBN)(this.auctionStartTime).toString('hex').padStart(8, '0') +
|
|
37
31
|
(0, utils_1.toBN)(this.duration).toString('hex').padStart(6, '0') +
|
|
38
|
-
(0, utils_1.toBN)(this.initialRateBump)
|
|
39
|
-
.toString('hex')
|
|
40
|
-
.padStart(6, '0') +
|
|
32
|
+
(0, utils_1.toBN)(this.initialRateBump).toString('hex').padStart(6, '0') +
|
|
41
33
|
(0, utils_1.toBN)(this.bankFee).toString('hex').padStart(8, '0') +
|
|
42
|
-
(0, utils_1.toBN)(this.salt).toString('hex').padStart(36, '0')
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
'Some inputs were out of allowed ranges'
|
|
46
|
-
)
|
|
47
|
-
return (0, utils_1.toBN)('0x' + res).toString()
|
|
34
|
+
(0, utils_1.toBN)(this.salt).toString('hex').padStart(36, '0');
|
|
35
|
+
(0, assert_1.default)(res.length === 64, 'Some inputs were out of allowed ranges');
|
|
36
|
+
return (0, utils_1.toBN)('0x' + res).toString();
|
|
48
37
|
}
|
|
49
38
|
}
|
|
50
|
-
exports.AuctionSalt = AuctionSalt
|
|
51
|
-
//# sourceMappingURL=auction-salt.js.map
|
|
39
|
+
exports.AuctionSalt = AuctionSalt;
|
|
40
|
+
//# sourceMappingURL=auction-salt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {}
|
|
1
|
+
export {};
|
|
@@ -1,70 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
const tslib_1 = require(
|
|
4
|
-
const auction_salt_1 = require(
|
|
5
|
-
const crypto_1 = tslib_1.__importDefault(require(
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const auction_salt_1 = require("./auction-salt");
|
|
5
|
+
const crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
6
6
|
describe('Auction Salt', () => {
|
|
7
|
-
jest.spyOn(crypto_1.default, 'randomInt').mockImplementation(() => 1000)
|
|
7
|
+
jest.spyOn(crypto_1.default, 'randomInt').mockImplementation(() => 1000);
|
|
8
8
|
it('should create salt', () => {
|
|
9
9
|
const salt = new auction_salt_1.AuctionSalt({
|
|
10
10
|
duration: 180,
|
|
11
11
|
auctionStartTime: 1673548149,
|
|
12
12
|
initialRateBump: 50000,
|
|
13
13
|
bankFee: '0'
|
|
14
|
-
})
|
|
15
|
-
expect(salt.build()).toBe(
|
|
16
|
-
|
|
17
|
-
)
|
|
18
|
-
})
|
|
14
|
+
});
|
|
15
|
+
expect(salt.build()).toBe('45118768841948961586167738353692277076075522015101619148498725069326976549864');
|
|
16
|
+
});
|
|
19
17
|
it('should create salt with non zero bank fee', () => {
|
|
20
18
|
const salt = new auction_salt_1.AuctionSalt({
|
|
21
19
|
duration: 180,
|
|
22
20
|
auctionStartTime: 1673548149,
|
|
23
21
|
initialRateBump: 50000,
|
|
24
22
|
bankFee: '123123123'
|
|
25
|
-
})
|
|
26
|
-
expect(salt.build()).toBe(
|
|
27
|
-
|
|
28
|
-
)
|
|
29
|
-
})
|
|
23
|
+
});
|
|
24
|
+
expect(salt.build()).toBe('45118768841948961586167741099429671146420854337050268925130474518618971309032');
|
|
25
|
+
});
|
|
30
26
|
it('should fail to create salt due to wrong auction start time', () => {
|
|
31
27
|
const salt = new auction_salt_1.AuctionSalt({
|
|
32
28
|
duration: 180,
|
|
33
29
|
auctionStartTime: 1673548149 * 1000,
|
|
34
30
|
initialRateBump: 50000,
|
|
35
31
|
bankFee: '123123123'
|
|
36
|
-
})
|
|
37
|
-
expect(() => salt.build()).toThrow(
|
|
38
|
-
|
|
39
|
-
)
|
|
40
|
-
})
|
|
32
|
+
});
|
|
33
|
+
expect(() => salt.build()).toThrow('Some inputs were out of allowed ranges');
|
|
34
|
+
});
|
|
41
35
|
it('should fail to create salt due to initial rate bump out of range', () => {
|
|
42
36
|
const salt = new auction_salt_1.AuctionSalt({
|
|
43
37
|
duration: 180,
|
|
44
38
|
auctionStartTime: 1673548149,
|
|
45
39
|
initialRateBump: 16777215 + 1,
|
|
46
40
|
bankFee: '123123123'
|
|
47
|
-
})
|
|
48
|
-
expect(() => salt.build()).toThrow(
|
|
49
|
-
|
|
50
|
-
)
|
|
51
|
-
})
|
|
41
|
+
});
|
|
42
|
+
expect(() => salt.build()).toThrow('Some inputs were out of allowed ranges');
|
|
43
|
+
});
|
|
52
44
|
it('should fail to create salt due to wrong duration', () => {
|
|
53
45
|
const salt = new auction_salt_1.AuctionSalt({
|
|
54
46
|
duration: 16777215 + 1,
|
|
55
47
|
auctionStartTime: 1673548149,
|
|
56
48
|
initialRateBump: 50000,
|
|
57
49
|
bankFee: '123123123'
|
|
58
|
-
})
|
|
59
|
-
expect(() => salt.build()).toThrow(
|
|
60
|
-
|
|
61
|
-
)
|
|
62
|
-
})
|
|
50
|
+
});
|
|
51
|
+
expect(() => salt.build()).toThrow('Some inputs were out of allowed ranges');
|
|
52
|
+
});
|
|
63
53
|
it('should decode salt', () => {
|
|
64
|
-
const encodedSalt =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
//# sourceMappingURL=auction.salt.spec.js.map
|
|
54
|
+
const encodedSalt = '45118768841948961586167741099429671146420854337050268925130474518618971309032';
|
|
55
|
+
const salt = auction_salt_1.AuctionSalt.decode(encodedSalt);
|
|
56
|
+
expect(salt.build()).toBe(encodedSalt);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=auction.salt.spec.js.map
|
package/auction-salt/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './auction-salt'
|
|
2
|
-
export * from './types'
|
|
3
|
-
export * from './parser/index'
|
|
1
|
+
export * from './auction-salt';
|
|
2
|
+
export * from './types';
|
|
3
|
+
export * from './parser/index';
|
package/auction-salt/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
const tslib_1 = require(
|
|
4
|
-
tslib_1.__exportStar(require(
|
|
5
|
-
tslib_1.__exportStar(require(
|
|
6
|
-
tslib_1.__exportStar(require(
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./auction-salt"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./parser/index"), exports);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
|
-
export declare const TIME_START_MASK: import(
|
|
3
|
-
export declare const DURATION_MASK: import(
|
|
4
|
-
export declare const INITIAL_RATE_BUMP_MASK: import(
|
|
5
|
-
export declare const FEE_MASK: import(
|
|
6
|
-
export declare const SALT_MASK: import(
|
|
7
|
-
export declare const TIME_START_SHIFT = 224
|
|
8
|
-
export declare const DURATION_SHIFT = 200
|
|
9
|
-
export declare const INITIAL_RATE_BUMP_SHIFT = 176
|
|
10
|
-
export declare const FEE_SHIFT = 144
|
|
2
|
+
export declare const TIME_START_MASK: import("bn.js");
|
|
3
|
+
export declare const DURATION_MASK: import("bn.js");
|
|
4
|
+
export declare const INITIAL_RATE_BUMP_MASK: import("bn.js");
|
|
5
|
+
export declare const FEE_MASK: import("bn.js");
|
|
6
|
+
export declare const SALT_MASK: import("bn.js");
|
|
7
|
+
export declare const TIME_START_SHIFT = 224;
|
|
8
|
+
export declare const DURATION_SHIFT = 200;
|
|
9
|
+
export declare const INITIAL_RATE_BUMP_SHIFT = 176;
|
|
10
|
+
export declare const FEE_SHIFT = 144;
|