@1inch/fusion-sdk 2.4.3 → 2.4.4
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/cjs/amount-calculator/amount-calculator.js +1 -1
- package/dist/cjs/amount-calculator/amount-calculator.spec.js +44 -2
- package/dist/esm/amount-calculator/amount-calculator.js +2 -2
- package/dist/esm/amount-calculator/amount-calculator.spec.js +44 -2
- package/dist/esm/package.json +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -221,7 +221,7 @@ function _define_property(obj, key, value) {
|
|
|
221
221
|
* @param makingAmount making amount to be filled
|
|
222
222
|
* @param orderMakingAmount full order making amount
|
|
223
223
|
*/ function _getSurplusFee(userTakingAmount, makingAmount, orderMakingAmount) {
|
|
224
|
-
var estimatedTakingAmount = (0, _limitordersdk.mulDiv)(this.surplus.estimatedTakerAmount, makingAmount, orderMakingAmount);
|
|
224
|
+
var estimatedTakingAmount = (0, _limitordersdk.mulDiv)(this.surplus.estimatedTakerAmount, makingAmount, orderMakingAmount, _limitordersdk.Rounding.Ceil);
|
|
225
225
|
if (userTakingAmount > estimatedTakingAmount) {
|
|
226
226
|
var surplusFee = (userTakingAmount - estimatedTakingAmount) * BigInt(this.surplus.protocolFee.toPercent()) / 100n;
|
|
227
227
|
return surplusFee;
|
|
@@ -62,5 +62,47 @@ describe('AmountCalculator', function() {
|
|
|
62
62
|
expect(userAmount).toBeGreaterThan(userAmountWithChargedSurplus);
|
|
63
63
|
expect(userAmount - userAmountWithChargedSurplus).toEqual(surplus / 2n);
|
|
64
64
|
});
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
// fee is 50%
|
|
66
|
+
it('should apply surplus with correct rounding', function() {
|
|
67
|
+
var startTime = 1764548287n;
|
|
68
|
+
var execTime = startTime;
|
|
69
|
+
var auction = new _index.AuctionCalculator(startTime, 600n, 179149n, [
|
|
70
|
+
{
|
|
71
|
+
coefficient: 157277,
|
|
72
|
+
delay: 84
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
coefficient: 141862,
|
|
76
|
+
delay: 84
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
coefficient: 129415,
|
|
80
|
+
delay: 84
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
coefficient: 116876,
|
|
84
|
+
delay: 84
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
coefficient: 24,
|
|
88
|
+
delay: 264
|
|
89
|
+
}
|
|
90
|
+
], {
|
|
91
|
+
gasBumpEstimate: 24n,
|
|
92
|
+
gasPriceEstimate: 221n
|
|
93
|
+
});
|
|
94
|
+
var taker = _limitordersdk.Address.fromBigInt(1n);
|
|
95
|
+
var feeCalculator = new _limitordersdk.FeeTakerExt.FeeCalculator(_index2.Fees.integratorFee(new _index2.IntegratorFee(new _limitordersdk.Address('0x0000000000000000000000000000000000000000'), new _limitordersdk.Address('0x0000000000000000000000000000000000000000'), new _limitordersdk.Bps(0n), new _limitordersdk.Bps(0n))), _index1.Whitelist.new(1764548263n, [
|
|
96
|
+
{
|
|
97
|
+
address: taker,
|
|
98
|
+
allowFrom: 0n
|
|
99
|
+
}
|
|
100
|
+
]));
|
|
101
|
+
var makingAmountOrder = 1369521200000n;
|
|
102
|
+
var calculator = new _amountcalculator.AmountCalculator(auction, feeCalculator, new _index1.SurplusParams(107289453867377650931124n, _limitordersdk.Bps.fromPercent(90)));
|
|
103
|
+
var userAmount1 = calculator.getSurplusFee(taker, 982226837n, 76145644627284979970n, makingAmountOrder, execTime, 216836903n);
|
|
104
|
+
expect(userAmount1).toBe(505013885259508359n);
|
|
105
|
+
var userAmount2 = calculator.getSurplusFee(taker, 136853897316n, 10609390660421433527440n, makingAmountOrder, execTime + 4n, 242000680n);
|
|
106
|
+
expect(userAmount2).toBe(69365890784904718356n);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
@@ -30,7 +30,7 @@ function _define_property(obj, key, value) {
|
|
|
30
30
|
}
|
|
31
31
|
return obj;
|
|
32
32
|
}
|
|
33
|
-
import { Bps, mulDiv, Rounding
|
|
33
|
+
import { Bps, FeeTakerExt, mulDiv, Rounding } from '@1inch/limit-order-sdk';
|
|
34
34
|
import { AuctionCalculator } from './auction-calculator/index.js';
|
|
35
35
|
import { SurplusParams } from '../fusion-order/index.js';
|
|
36
36
|
import { Fees } from '../fusion-order/fees/index.js';
|
|
@@ -211,7 +211,7 @@ import { Fees } from '../fusion-order/fees/index.js';
|
|
|
211
211
|
* @param makingAmount making amount to be filled
|
|
212
212
|
* @param orderMakingAmount full order making amount
|
|
213
213
|
*/ function _getSurplusFee(userTakingAmount, makingAmount, orderMakingAmount) {
|
|
214
|
-
var estimatedTakingAmount = mulDiv(this.surplus.estimatedTakerAmount, makingAmount, orderMakingAmount);
|
|
214
|
+
var estimatedTakingAmount = mulDiv(this.surplus.estimatedTakerAmount, makingAmount, orderMakingAmount, Rounding.Ceil);
|
|
215
215
|
if (userTakingAmount > estimatedTakingAmount) {
|
|
216
216
|
var surplusFee = (userTakingAmount - estimatedTakingAmount) * BigInt(this.surplus.protocolFee.toPercent()) / 100n;
|
|
217
217
|
return surplusFee;
|
|
@@ -58,5 +58,47 @@ describe('AmountCalculator', function() {
|
|
|
58
58
|
expect(userAmount).toBeGreaterThan(userAmountWithChargedSurplus);
|
|
59
59
|
expect(userAmount - userAmountWithChargedSurplus).toEqual(surplus / 2n);
|
|
60
60
|
});
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
// fee is 50%
|
|
62
|
+
it('should apply surplus with correct rounding', function() {
|
|
63
|
+
var startTime = 1764548287n;
|
|
64
|
+
var execTime = startTime;
|
|
65
|
+
var auction = new AuctionCalculator(startTime, 600n, 179149n, [
|
|
66
|
+
{
|
|
67
|
+
coefficient: 157277,
|
|
68
|
+
delay: 84
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
coefficient: 141862,
|
|
72
|
+
delay: 84
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
coefficient: 129415,
|
|
76
|
+
delay: 84
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
coefficient: 116876,
|
|
80
|
+
delay: 84
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
coefficient: 24,
|
|
84
|
+
delay: 264
|
|
85
|
+
}
|
|
86
|
+
], {
|
|
87
|
+
gasBumpEstimate: 24n,
|
|
88
|
+
gasPriceEstimate: 221n
|
|
89
|
+
});
|
|
90
|
+
var taker = Address.fromBigInt(1n);
|
|
91
|
+
var feeCalculator = new FeeTakerExt.FeeCalculator(Fees.integratorFee(new IntegratorFee(new Address('0x0000000000000000000000000000000000000000'), new Address('0x0000000000000000000000000000000000000000'), new Bps(0n), new Bps(0n))), Whitelist.new(1764548263n, [
|
|
92
|
+
{
|
|
93
|
+
address: taker,
|
|
94
|
+
allowFrom: 0n
|
|
95
|
+
}
|
|
96
|
+
]));
|
|
97
|
+
var makingAmountOrder = 1369521200000n;
|
|
98
|
+
var calculator = new AmountCalculator(auction, feeCalculator, new SurplusParams(107289453867377650931124n, Bps.fromPercent(90)));
|
|
99
|
+
var userAmount1 = calculator.getSurplusFee(taker, 982226837n, 76145644627284979970n, makingAmountOrder, execTime, 216836903n);
|
|
100
|
+
expect(userAmount1).toBe(505013885259508359n);
|
|
101
|
+
var userAmount2 = calculator.getSurplusFee(taker, 136853897316n, 10609390660421433527440n, makingAmountOrder, execTime + 4n, 242000680n);
|
|
102
|
+
expect(userAmount2).toBe(69365890784904718356n);
|
|
103
|
+
});
|
|
104
|
+
});
|
package/dist/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@1inch/fusion-sdk","version":"2.4.
|
|
1
|
+
{"name":"@1inch/fusion-sdk","version":"2.4.4","type":"module"}
|