@1inch/fusion-sdk 0.0.5 → 0.0.6
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/api/fusion-api.d.ts +25 -16
- package/api/fusion-api.js +36 -26
- 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 +479 -395
- package/api/orders/order-api.spec.js.map +1 -1
- package/api/orders/orders.api.d.ts +24 -10
- package/api/orders/orders.api.js +30 -28
- package/api/orders/orders.request.d.ts +22 -18
- package/api/orders/orders.request.js +40 -31
- package/api/orders/types.d.ts +59 -57
- package/api/orders/types.js +17 -16
- package/api/orders/types.js.map +1 -1
- 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 +28 -21
- package/api/params.d.ts +3 -1
- package/api/params.js +25 -19
- 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 +19 -17
- 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 +6 -6
- package/api/quoter/quote/order-params.js +12 -12
- package/api/quoter/quote/quote.d.ts +26 -21
- package/api/quoter/quote/quote.js +85 -52
- package/api/quoter/quote/quote.js.map +1 -1
- package/api/quoter/quote/types.d.ts +4 -4
- package/api/quoter/quote/types.js +3 -3
- package/api/quoter/quoter.api.d.ts +12 -9
- 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 +32 -23
- 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 +28 -26
- package/api/quoter/types.d.ts +45 -44
- package/api/quoter/types.js +10 -10
- package/api/quoter/types.js.map +1 -1
- package/api/relayer/index.d.ts +3 -3
- package/api/relayer/index.js +7 -7
- package/api/relayer/relayer.api.d.ts +12 -9
- 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 +96 -79
- 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 +17 -15
- package/api/types.js +3 -3
- package/auction-calculator/auction-calculator.d.ts +22 -13
- package/auction-calculator/auction-calculator.js +70 -45
- package/auction-calculator/auction-calculator.spec.d.ts +1 -1
- package/auction-calculator/auction-calculator.spec.js +45 -32
- package/auction-calculator/calc.d.ts +8 -2
- 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 +34 -23
- package/auction-salt/auction.salt.spec.d.ts +1 -1
- package/auction-salt/auction.salt.spec.js +38 -27
- 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 +33 -14
- 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 +33 -22
- 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 +36 -23
- package/auction-suffix/auction-suffix.spec.d.ts +1 -1
- package/auction-suffix/auction-suffix.spec.js +20 -15
- package/auction-suffix/constants.d.ts +1 -1
- package/auction-suffix/constants.js +5 -5
- package/auction-suffix/encoder.d.ts +15 -6
- package/auction-suffix/encoder.js +45 -28
- 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 +30 -17
- package/auction-suffix/parser/errors.d.ts +1 -2
- package/auction-suffix/parser/errors.js +6 -7
- package/auction-suffix/parser/index.d.ts +4 -4
- package/auction-suffix/parser/index.js +8 -8
- package/auction-suffix/parser/parser.d.ts +28 -8
- package/auction-suffix/parser/parser.js +162 -81
- 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 +6 -3
- 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 +15 -10
- 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 +36 -23
- package/connector/blockchain/web3-provider-connector.d.ts +13 -8
- package/connector/blockchain/web3-provider-connector.js +12 -9
- package/connector/blockchain/web3-provider.connector.spec.d.ts +1 -1
- package/connector/blockchain/web3-provider.connector.spec.js +37 -26
- 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 +37 -31
- 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 +10 -6
- package/constants.js +23 -16
- package/fusion-order/fusion-order.d.ts +17 -7
- package/fusion-order/fusion-order.js +14 -12
- package/fusion-order/fusion-order.spec.d.ts +1 -1
- package/fusion-order/fusion-order.spec.js +27 -22
- 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 +10 -9
- package/limit-order/eip712/domain.js +28 -23
- package/limit-order/eip712/eip712.types.d.ts +19 -15
- 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 +17 -6
- package/limit-order/eip712/order-typed-data-builder.js +34 -19
- 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 +31 -25
- package/limit-order/limit-order.js +103 -50
- package/limit-order/limit-order.spec.d.ts +1 -1
- package/limit-order/limit-order.spec.js +75 -51
- 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 +5 -2
- package/limit-order/parser/parser.js +23 -18
- package/limit-order/parser/types.d.ts +3 -3
- package/limit-order/parser/types.js +3 -3
- package/limit-order/predicate-factory.d.ts +9 -5
- package/limit-order/predicate-factory.js +40 -24
- package/limit-order/predicate-factory.spec.d.ts +1 -1
- package/limit-order/predicate-factory.spec.js +44 -29
- 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 +29 -11
- package/sdk/sdk.js +48 -38
- 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 +26 -12
- package/settlement/encoders/index.d.ts +3 -3
- package/settlement/encoders/index.js +7 -7
- package/settlement/encoders/settlement.encoder.d.ts +13 -4
- package/settlement/encoders/settlement.encoder.js +41 -19
- package/settlement/index.d.ts +4 -4
- package/settlement/index.js +8 -8
- package/settlement/settlement.d.ts +8 -5
- package/settlement/settlement.js +28 -14
- package/settlement/settlement.spec.d.ts +1 -1
- package/settlement/settlement.spec.js +45 -35
- package/settlement/signature-patcher.d.ts +1 -1
- package/settlement/signature-patcher.js +19 -16
- package/settlement/types.d.ts +13 -13
- package/settlement/types.js +3 -3
- package/utils.d.ts +6 -6
- package/utils.js +29 -23
- package/validations.d.ts +2 -2
- package/validations.js +14 -15
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.RelayerRequest = void 0
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', {value: true})
|
|
3
|
+
exports.RelayerRequest = void 0
|
|
4
4
|
class RelayerRequest {
|
|
5
5
|
constructor(params) {
|
|
6
|
-
this.order = params.order
|
|
7
|
-
this.signature = params.signature
|
|
8
|
-
this.quoteId = params.quoteId
|
|
6
|
+
this.order = params.order
|
|
7
|
+
this.signature = params.signature
|
|
8
|
+
this.quoteId = params.quoteId
|
|
9
9
|
}
|
|
10
10
|
static new(params) {
|
|
11
|
-
return new RelayerRequest(params)
|
|
11
|
+
return new RelayerRequest(params)
|
|
12
12
|
}
|
|
13
13
|
build() {
|
|
14
14
|
return {
|
|
15
15
|
order: this.order,
|
|
16
16
|
signature: this.signature,
|
|
17
17
|
quoteId: this.quoteId
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
exports.RelayerRequest = RelayerRequest
|
|
22
|
-
//# sourceMappingURL=relayer.request.js.map
|
|
21
|
+
exports.RelayerRequest = RelayerRequest
|
|
22
|
+
//# sourceMappingURL=relayer.request.js.map
|
package/api/relayer/types.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {NetworkEnum} from '../../constants'
|
|
2
|
+
import {LimitOrderV3Struct} from '../../limit-order'
|
|
3
3
|
export declare type RelayerRequestParams = {
|
|
4
|
-
order: LimitOrderV3Struct
|
|
5
|
-
signature: string
|
|
6
|
-
quoteId: string
|
|
7
|
-
}
|
|
4
|
+
order: LimitOrderV3Struct
|
|
5
|
+
signature: string
|
|
6
|
+
quoteId: string
|
|
7
|
+
}
|
|
8
8
|
export declare type RelayerApiConfig = {
|
|
9
|
-
network: NetworkEnum
|
|
10
|
-
url: string
|
|
11
|
-
}
|
|
9
|
+
network: NetworkEnum
|
|
10
|
+
url: string
|
|
11
|
+
}
|
package/api/relayer/types.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
//# sourceMappingURL=types.js.map
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', {value: true})
|
|
3
|
+
//# sourceMappingURL=types.js.map
|
package/api/types.d.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {NetworkEnum} from '../constants'
|
|
2
|
+
import {HttpProviderConnector} from '../connector'
|
|
3
3
|
export declare type FusionApiConfig = {
|
|
4
|
-
url: string
|
|
5
|
-
network: NetworkEnum
|
|
6
|
-
httpProvider?: HttpProviderConnector
|
|
7
|
-
}
|
|
4
|
+
url: string
|
|
5
|
+
network: NetworkEnum
|
|
6
|
+
httpProvider?: HttpProviderConnector
|
|
7
|
+
}
|
|
8
8
|
export declare type PaginationMeta = {
|
|
9
|
-
totalItems: number
|
|
10
|
-
itemsPerPage: number
|
|
11
|
-
totalPages: number
|
|
12
|
-
currentPage: number
|
|
13
|
-
}
|
|
14
|
-
export declare type PaginationOutput<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
totalItems: number
|
|
10
|
+
itemsPerPage: number
|
|
11
|
+
totalPages: number
|
|
12
|
+
currentPage: number
|
|
13
|
+
}
|
|
14
|
+
export declare type PaginationOutput<
|
|
15
|
+
T extends Record<string, any> = Record<string, any>
|
|
16
|
+
> = {
|
|
17
|
+
meta: PaginationMeta
|
|
18
|
+
items: T[]
|
|
19
|
+
}
|
package/api/types.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
//# sourceMappingURL=types.js.map
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', {value: true})
|
|
3
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -1,19 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
5
|
+
private readonly startTime
|
|
6
|
+
private readonly duration
|
|
7
|
+
private readonly initialRateBump
|
|
8
|
+
private readonly points
|
|
9
|
+
private readonly takerFeeRatio
|
|
10
|
+
constructor(
|
|
11
|
+
startTime: number,
|
|
12
|
+
duration: number,
|
|
13
|
+
initialRateBump: number,
|
|
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
|
|
14
23
|
/**
|
|
15
24
|
* @see https://github.com/1inch/limit-order-settlement/blob/3c7cf9eacbaf7a60624d7a6f069c59d809f2204a/contracts/libraries/OrderSuffix.sol#L75
|
|
16
25
|
* @param time auction timestamp in seconds
|
|
17
26
|
*/
|
|
18
|
-
calcRateBump(time: number): number
|
|
27
|
+
calcRateBump(time: number): number
|
|
19
28
|
}
|
|
@@ -1,71 +1,96 @@
|
|
|
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(
|
|
23
|
+
return new AuctionCalculator(
|
|
24
|
+
salt.auctionStartTime,
|
|
25
|
+
salt.duration,
|
|
26
|
+
salt.initialRateBump,
|
|
27
|
+
suffix.points,
|
|
28
|
+
suffix.takerFeeRatio
|
|
29
|
+
)
|
|
24
30
|
}
|
|
25
31
|
calcAuctionTakingAmount(takingAmount, rate) {
|
|
26
32
|
const auctionTakingAmount = bignumber_1.BigNumber.from(takingAmount)
|
|
27
|
-
.mul(
|
|
28
|
-
|
|
33
|
+
.mul(
|
|
34
|
+
bignumber_1.BigNumber.from(rate).add(
|
|
35
|
+
constants_1.RATE_BUMP_DENOMINATOR
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
.div(constants_1.RATE_BUMP_DENOMINATOR)
|
|
29
39
|
if (this.takerFeeRatio === '0') {
|
|
30
|
-
return auctionTakingAmount.toString()
|
|
40
|
+
return auctionTakingAmount.toString()
|
|
31
41
|
}
|
|
32
42
|
return auctionTakingAmount
|
|
33
|
-
.add(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
.add(
|
|
44
|
+
auctionTakingAmount
|
|
45
|
+
.mul(this.takerFeeRatio)
|
|
46
|
+
.div(auction_suffix_1.CONTRACT_TAKER_FEE_PRECISION)
|
|
47
|
+
)
|
|
48
|
+
.toString()
|
|
37
49
|
}
|
|
38
50
|
/**
|
|
39
51
|
* @see https://github.com/1inch/limit-order-settlement/blob/3c7cf9eacbaf7a60624d7a6f069c59d809f2204a/contracts/libraries/OrderSuffix.sol#L75
|
|
40
52
|
* @param time auction timestamp in seconds
|
|
41
53
|
*/
|
|
42
54
|
calcRateBump(time) {
|
|
43
|
-
let cumulativeTime = bignumber_1.BigNumber.from(this.startTime)
|
|
44
|
-
const lastTime = bignumber_1.BigNumber.from(this.duration).add(
|
|
45
|
-
|
|
46
|
-
|
|
55
|
+
let cumulativeTime = bignumber_1.BigNumber.from(this.startTime)
|
|
56
|
+
const lastTime = bignumber_1.BigNumber.from(this.duration).add(
|
|
57
|
+
cumulativeTime
|
|
58
|
+
)
|
|
59
|
+
const startBump = bignumber_1.BigNumber.from(this.initialRateBump)
|
|
60
|
+
const currentTime = bignumber_1.BigNumber.from(time)
|
|
47
61
|
if (currentTime.lte(cumulativeTime)) {
|
|
48
|
-
return this.initialRateBump
|
|
62
|
+
return this.initialRateBump
|
|
63
|
+
} else if (currentTime.gte(lastTime)) {
|
|
64
|
+
return 0
|
|
49
65
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
let prevCoefficient = startBump;
|
|
54
|
-
let prevCumulativeTime = cumulativeTime;
|
|
66
|
+
let prevCoefficient = startBump
|
|
67
|
+
let prevCumulativeTime = cumulativeTime
|
|
55
68
|
for (let i = this.points.length - 1; i >= 0; i--) {
|
|
56
|
-
const {
|
|
57
|
-
cumulativeTime = cumulativeTime.add(delay)
|
|
58
|
-
const coefficientBN = bignumber_1.BigNumber.from(coefficient)
|
|
69
|
+
const {coefficient, delay} = this.points[i]
|
|
70
|
+
cumulativeTime = cumulativeTime.add(delay)
|
|
71
|
+
const coefficientBN = bignumber_1.BigNumber.from(coefficient)
|
|
59
72
|
if (cumulativeTime.gt(currentTime)) {
|
|
60
|
-
const rate = (0, calc_1.linearInterpolation)(
|
|
61
|
-
|
|
73
|
+
const rate = (0, calc_1.linearInterpolation)(
|
|
74
|
+
prevCumulativeTime,
|
|
75
|
+
cumulativeTime,
|
|
76
|
+
prevCoefficient,
|
|
77
|
+
coefficientBN,
|
|
78
|
+
currentTime
|
|
79
|
+
)
|
|
80
|
+
return rate.toNumber()
|
|
62
81
|
}
|
|
63
|
-
prevCumulativeTime = cumulativeTime
|
|
64
|
-
prevCoefficient = coefficientBN
|
|
82
|
+
prevCumulativeTime = cumulativeTime
|
|
83
|
+
prevCoefficient = coefficientBN
|
|
65
84
|
}
|
|
66
|
-
const rate = (0, calc_1.linearInterpolation)(
|
|
67
|
-
|
|
85
|
+
const rate = (0, calc_1.linearInterpolation)(
|
|
86
|
+
prevCumulativeTime,
|
|
87
|
+
lastTime,
|
|
88
|
+
prevCoefficient,
|
|
89
|
+
bignumber_1.BigNumber.from(0),
|
|
90
|
+
currentTime
|
|
91
|
+
)
|
|
92
|
+
return rate.toNumber()
|
|
68
93
|
}
|
|
69
94
|
}
|
|
70
|
-
exports.AuctionCalculator = AuctionCalculator
|
|
71
|
-
//# sourceMappingURL=auction-calculator.js.map
|
|
95
|
+
exports.AuctionCalculator = AuctionCalculator
|
|
96
|
+
//# sourceMappingURL=auction-calculator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {}
|
|
1
|
+
export {}
|
|
@@ -1,35 +1,48 @@
|
|
|
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
|
-
|
|
8
|
+
const calculator =
|
|
9
|
+
auction_calculator_1.AuctionCalculator.fromLimitOrderV3Struct({
|
|
10
|
+
allowedSender: '0x0000000000000000000000000000000000000000',
|
|
11
|
+
interactions:
|
|
12
|
+
'0x000c004e200000000000000000219ab540356cbb839cbe05303d7705faf486570009',
|
|
13
|
+
maker: '0x00000000219ab540356cbb839cbe05303d7705fa',
|
|
14
|
+
makerAsset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
15
|
+
makingAmount: '1000000000000000000',
|
|
16
|
+
offsets: '0',
|
|
17
|
+
receiver: '0x0000000000000000000000000000000000000000',
|
|
18
|
+
salt: '45118768841948961586167738353692277076075522015101619148498725069326976558864',
|
|
19
|
+
takerAsset: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
20
|
+
takingAmount: '1420000000'
|
|
21
|
+
})
|
|
22
|
+
const rate = calculator.calcRateBump(1673548209)
|
|
23
|
+
const auctionTakingAmount = calculator.calcAuctionTakingAmount(
|
|
24
|
+
'1420000000',
|
|
25
|
+
rate
|
|
26
|
+
)
|
|
27
|
+
expect(rate).toBe(14285)
|
|
28
|
+
expect(auctionTakingAmount).toBe('1422028470')
|
|
29
|
+
})
|
|
25
30
|
it('should be created successfully from suffix and salt', () => {
|
|
26
|
-
const suffix = auction_suffix_1.AuctionSuffix.decode(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
const suffix = auction_suffix_1.AuctionSuffix.decode(
|
|
32
|
+
'0x000c004e200000000000000000219ab540356cbb839cbe05303d7705faf486570009'
|
|
33
|
+
)
|
|
34
|
+
const salt = auction_salt_1.AuctionSalt.decode(
|
|
35
|
+
'45118768841948961586167738353692277076075522015101619148498725069326976558864'
|
|
36
|
+
)
|
|
37
|
+
const calculator =
|
|
38
|
+
auction_calculator_1.AuctionCalculator.fromAuctionData(suffix, salt)
|
|
39
|
+
const rate = calculator.calcRateBump(1673548209)
|
|
40
|
+
const auctionTakingAmount = calculator.calcAuctionTakingAmount(
|
|
41
|
+
'1420000000',
|
|
42
|
+
rate
|
|
43
|
+
)
|
|
44
|
+
expect(rate).toBe(14285)
|
|
45
|
+
expect(auctionTakingAmount).toBe('1422028470')
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
//# sourceMappingURL=auction-calculator.spec.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {BigNumber} from '@ethersproject/bignumber'
|
|
2
2
|
/**
|
|
3
3
|
*
|
|
4
4
|
* v2(t-t1) + v1(t2-t)
|
|
@@ -7,4 +7,10 @@ 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(
|
|
10
|
+
export declare function linearInterpolation(
|
|
11
|
+
t1: BigNumber,
|
|
12
|
+
t2: BigNumber,
|
|
13
|
+
v1: BigNumber,
|
|
14
|
+
v2: BigNumber,
|
|
15
|
+
t: BigNumber
|
|
16
|
+
): 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
|
|
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 {
|
|
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,21 +1,24 @@
|
|
|
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
|
-
|
|
11
|
+
if (
|
|
12
|
+
auction.salt &&
|
|
13
|
+
parser_1.SALT_MASK.lt((0, utils_1.toBN)(auction.salt))
|
|
14
|
+
) {
|
|
15
|
+
throw new Error('salt should be less 18 bytes')
|
|
13
16
|
}
|
|
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
|
|
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
|
|
19
22
|
}
|
|
20
23
|
static decode(salt) {
|
|
21
24
|
return new AuctionSalt({
|
|
@@ -24,17 +27,25 @@ class AuctionSalt {
|
|
|
24
27
|
duration: (0, parser_1.getDuration)(salt).toNumber(),
|
|
25
28
|
bankFee: (0, parser_1.getFee)(salt).toString(),
|
|
26
29
|
initialRateBump: (0, parser_1.getInitialRateBump)(salt).toNumber()
|
|
27
|
-
})
|
|
30
|
+
})
|
|
28
31
|
}
|
|
29
32
|
build() {
|
|
30
|
-
const res =
|
|
33
|
+
const res =
|
|
34
|
+
(0, utils_1.toBN)(this.auctionStartTime)
|
|
35
|
+
.toString('hex')
|
|
36
|
+
.padStart(8, '0') +
|
|
31
37
|
(0, utils_1.toBN)(this.duration).toString('hex').padStart(6, '0') +
|
|
32
|
-
(0, utils_1.toBN)(this.initialRateBump)
|
|
38
|
+
(0, utils_1.toBN)(this.initialRateBump)
|
|
39
|
+
.toString('hex')
|
|
40
|
+
.padStart(6, '0') +
|
|
33
41
|
(0, utils_1.toBN)(this.bankFee).toString('hex').padStart(8, '0') +
|
|
34
|
-
(0, utils_1.toBN)(this.salt).toString('hex').padStart(36, '0')
|
|
35
|
-
(0, assert_1.default)(
|
|
36
|
-
|
|
42
|
+
(0, utils_1.toBN)(this.salt).toString('hex').padStart(36, '0')
|
|
43
|
+
;(0, assert_1.default)(
|
|
44
|
+
res.length === 64,
|
|
45
|
+
'Some inputs were out of allowed ranges'
|
|
46
|
+
)
|
|
47
|
+
return (0, utils_1.toBN)('0x' + res).toString()
|
|
37
48
|
}
|
|
38
49
|
}
|
|
39
|
-
exports.AuctionSalt = AuctionSalt
|
|
40
|
-
//# sourceMappingURL=auction-salt.js.map
|
|
50
|
+
exports.AuctionSalt = AuctionSalt
|
|
51
|
+
//# sourceMappingURL=auction-salt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {}
|
|
1
|
+
export {}
|