|
5 | 5 | ### Real world example
|
6 | 6 |
|
7 | 7 | ```typescript
|
8 |
| -import {AuctionCalculator} from '@1inch/fusion-sdk' |
9 |
| - |
10 |
| -const limitOrderStruct = { |
11 |
| - allowedSender: '0x0000000000000000000000000000000000000000', |
12 |
| - interactions: |
13 |
| - '0x000c004e200000000000000000219ab540356cbb839cbe05303d7705faf486570009', |
14 |
| - maker: '0x00000000219ab540356cbb839cbe05303d7705fa', |
15 |
| - makerAsset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', |
16 |
| - makingAmount: '1000000000000000000', |
17 |
| - offsets: '0', |
18 |
| - receiver: '0x0000000000000000000000000000000000000000', |
19 |
| - salt: '45118768841948961586167738353692277076075522015101619148498725069326976558864', |
20 |
| - takerAsset: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', |
21 |
| - takingAmount: '1420000000' |
22 |
| -} |
23 |
| - |
24 |
| -const calculator = AuctionCalculator.fromLimitOrderV3Struct(limitOrderStruct) |
25 |
| -// #=> AuctionCalculator instance |
26 |
| - |
27 |
| -const rate = calculator.calcRateBump(1673548209) |
28 |
| -// #=> 14285 |
| 8 | +import { |
| 9 | + AuctionCalculator, |
| 10 | + SettlementPostInteractionData, |
| 11 | + AuctionDetails, |
| 12 | + Address, |
| 13 | + bpsToRatioFormat |
| 14 | +} from '@1inch/fusion-sdk' |
| 15 | + |
| 16 | +const startTime = 1673548149n |
| 17 | +const settlementData = SettlementPostInteractionData.new({ |
| 18 | + bankFee: 0n, |
| 19 | + auctionStartTime: startTime, |
| 20 | + whitelist: [ |
| 21 | + { |
| 22 | + address: new Address('0x111111111117dc0aa78b770fa6a738034120c302'), |
| 23 | + delay: 0n |
| 24 | + } |
| 25 | + ], |
| 26 | + integratorFee: { |
| 27 | + receiver: new Address('0x111111111117dc0aa78b770fa6a738034120c302'), |
| 28 | + ratio: bpsToRatioFormat(10) |
| 29 | + } |
| 30 | +}) |
| 31 | +const details = new AuctionDetails({ |
| 32 | + duration: 180n, // in seconds, |
| 33 | + startTime, // unix timestamp (in sec), |
| 34 | + initialRateBump: 50000, |
| 35 | + points: [ |
| 36 | + { |
| 37 | + delay: 10, // relative to auction start time |
| 38 | + coefficient: 40000 |
| 39 | + }, |
| 40 | + |
| 41 | + { |
| 42 | + delay: 10, // relative to previous point |
| 43 | + coefficient: 40000 |
| 44 | + } |
| 45 | + ] |
| 46 | +}) |
| 47 | +const calculator = AuctionCalculator.fromAuctionData(settlementData, details) // #=> AuctionCalculator instance |
| 48 | + |
| 49 | +const rate = calculator.calcRateBump(1673548160) |
| 50 | +// #=> 40000 |
29 | 51 |
|
30 | 52 | const auctionTakingAmount = calculator.calcAuctionTakingAmount(
|
31 | 53 | '1420000000',
|
32 | 54 | rate
|
33 | 55 | )
|
34 |
| -// #=> '1422028470' |
35 |
| -``` |
36 |
| - |
37 |
| -### static AuctionCalculator.fromLimitOrderV3Struct |
38 |
| - |
39 |
| -**Description:** used to create auction instance from limit order |
40 |
| - |
41 |
| -**Arguments:** accepts LimitOrderV3Struct as an argument |
42 |
| - |
43 |
| -| Name | Type | Inner Solidity Type | Description | |
44 |
| -| ------------- | ------ | ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
45 |
| -| salt | string | uint256 | some unique value. It is necessary to be able to create limit orders with the same parameters (so that they have a different hash) | |
46 |
| -| makerAsset | string | address | the address of the asset user want to sell (address of a token contract) | |
47 |
| -| takerAsset | string | address | the address of the asset user want to buy (address of a token contract) | |
48 |
| -| maker | string | address | the address of the limit order creator | |
49 |
| -| receiver | string | address | If it contains a zero address, which means that taker asset will be sent to the address of the creator of the limit order. If user set any other value, then taker asset will be sent to the specified address | |
50 |
| -| allowedSender | string | address | If it contains a zero address, which means that a limit order is available for everyone to fill. If user set any other value, then the limit order will be available for execution only for the specified address (private limit order) | |
51 |
| -| makingAmount | string | uint256 | amount of maker asset | |
52 |
| -| takingAmount | string | uint256 | amount of taker asset | |
53 |
| -| offsets | string | uint256 | every 32's bytes represents offset of the n'ths interaction | |
54 |
| -| interactions | string | bytes | used to encode fusion specific data | |
55 |
| - |
56 |
| -**Order.interactions suffix structure:** |
57 |
| - |
58 |
| -- M\*(1 + 3 bytes) - auction points coefficients with seconds delays |
59 |
| -- N\*(4 + 20 bytes) - resolver with corresponding time limit |
60 |
| -- 4 bytes - public time limit (started from this point of time an order can be full filled by anyone) |
61 |
| -- 32 bytes - taking fee (optional if flags has \_HAS_TAKING_FEE_FLAG) |
62 |
| -- 1 byte - flags |
63 |
| - |
64 |
| -**Examples:** |
65 |
| - |
66 |
| -```typescript |
67 |
| -import {AuctionCalculator} from '@1inch/fusion-sdk' |
68 |
| - |
69 |
| -const limitOrderStruct = { |
70 |
| - allowedSender: '0x0000000000000000000000000000000000000000', |
71 |
| - interactions: |
72 |
| - '0x000c004e200000000000000000219ab540356cbb839cbe05303d7705faf486570009', |
73 |
| - maker: '0x00000000219ab540356cbb839cbe05303d7705fa', |
74 |
| - makerAsset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', |
75 |
| - makingAmount: '1000000000000000000', |
76 |
| - offsets: '0', |
77 |
| - receiver: '0x0000000000000000000000000000000000000000', |
78 |
| - salt: '45118768841948961586167738353692277076075522015101619148498725069326976558864', |
79 |
| - takerAsset: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', |
80 |
| - takingAmount: '1420000000' |
81 |
| -} |
82 |
| - |
83 |
| -AuctionCalculator.fromLimitOrderV3Struct(limitOrderStruct) |
84 |
| -// #=> AuctionCalculator instance |
| 56 | +// #=> '1427105680' |
85 | 57 | ```
|
86 | 58 |
|
87 |
| -### AuctionCalculator.calcRateBump |
88 |
| - |
89 |
| -**Description:** used to calculate exchange rate in some point of time. user can read more about it [here](https://docs.1inch.io/docs/fusion-swap/introduction) |
90 | 59 |
|
91 |
| -**Arguments**: time (unix timestamp) |
92 |
| - |
93 |
| -### AuctionCalculator.calcAuctionTakingAmount |
94 |
| - |
95 |
| -**Description:** used to calculate taker amount |
96 |
| - |
97 |
| -**Arguments**: |
98 |
| - |
99 |
| -- [0] takingAmount: string |
100 |
| -- [1] rate: number |
101 |
| - |
102 |
| -### AuctionCalculator.fromAuctionData |
103 |
| - |
104 |
| -**Description:** creates AuctionCalculator from suffix and salt |
105 |
| - |
106 |
| -**Arguments:** |
107 |
| - |
108 |
| -- [0] suffix: [AuctionSuffix](src/auction-suffix/readme.md) |
109 |
| -- [1] salt: [AuctionSalt](src/auction-salt/readme.md) |
110 |
| - |
111 |
| -**Example:** |
112 |
| - |
113 |
| -```typescript |
114 |
| -import {AuctionSuffix, AuctionSalt, AuctionCalculator} from '@1inch/fusion-sdk' |
115 |
| - |
116 |
| -const suffix = AuctionSuffix.decode( |
117 |
| - '0x000c004e200000000000000000219ab540356cbb839cbe05303d7705faf486570009' |
118 |
| -) |
119 |
| -const salt = AuctionSalt.decode( |
120 |
| - '45118768841948961586167738353692277076075522015101619148498725069326976558864' |
121 |
| -) |
122 |
| -AuctionCalculator.fromAuctionData(suffix, salt) |
123 |
| -// #=> AuctionCalculator instance |
124 |
| -``` |
0 commit comments