Skip to content

Commit

Permalink
remove nonce manager
Browse files Browse the repository at this point in the history
  • Loading branch information
vbrvk committed Feb 29, 2024
1 parent 7b84e8d commit 48a93a3
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 114 deletions.
9 changes: 6 additions & 3 deletions src/api/quoter/quote/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,12 @@ export class Quote {
permit: params.permit
? this.params.fromTokenAddress + params.permit.substring(2)
: undefined,
allowPartialFills: paramsData?.allowPartialFills
},
auctionDetails.auctionStartTime + auctionDetails.duration + 32n
allowPartialFills: paramsData?.allowPartialFills,
deadline:
auctionDetails.auctionStartTime +
auctionDetails.duration +
32n
}
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const UNWRAPPER_CONTRACT_ADDRESS_MAP: Record<NetworkEnum, Address> = {
// todo: change addresses
export const SETTLEMENT_EXTENSION_ADDRESS_MAP: Record<NetworkEnum, Address> = {
[NetworkEnum.ETHEREUM]: new Address(
'0xf4f4d19c3ae690c412460a5948757180642364bf'
'0x8273f37417da37c4a6c3995e82cf442f87a25d9c'
),
[NetworkEnum.BINANCE]: new Address(
'0x1d0ae300eec4093cee4367c00b228d10a5c7ac63'
Expand Down
18 changes: 13 additions & 5 deletions src/fusion-order/fusion-order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {AuctionDetails} from '../auction-details'
import {PostInteractionData} from '../post-interaction-data'
import {NetworkEnum} from '../constants'
import {Address} from '../address'
import {MakerTraits} from '../limit-order'

describe('Fusion Order', () => {
it('should create fusion order', () => {
Expand Down Expand Up @@ -32,6 +33,7 @@ describe('Fusion Order', () => {
bankFee: 0n
})

const deadline = auctionStartTime + 180n
const order = new FusionOrder(
{
makerAsset: new Address(
Expand All @@ -50,20 +52,26 @@ describe('Fusion Order', () => {
},
auctionDetails,
postInteractionData,
{},
auctionStartTime + 180n
{deadline}
)

expect(order.build()).toStrictEqual({
const builtOrder = order.build()
expect(builtOrder).toStrictEqual({
maker: '0x00000000219ab540356cbb839cbe05303d7705fa',
makerAsset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
makingAmount: '1000000000000000000',
receiver: '0x0000000000000000000000000000000000000000',
takerAsset: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
takingAmount: '1420000000',
makerTraits:
'87748692625153679344424887076896305170056162277626525237169529665166579335168',
salt: '15789007877680932694984109183015996704174250167756'
'29852648006495581632639394572552351243421169944806243217440737661210014515200',
salt: '14832508939800728556409473652845244531014097925085'
})

const makerTraits = new MakerTraits(BigInt(builtOrder.makerTraits))
expect(makerTraits.isNativeUnwrapEnabled()).toEqual(false)
expect(makerTraits.expiration()).toEqual(deadline)
expect(makerTraits.nonceOrEpoch()).toEqual(0n)
expect(makerTraits.isPartialFilledAllowed()).toEqual(true)
})
})
39 changes: 28 additions & 11 deletions src/fusion-order/fusion-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,50 @@ export class FusionOrder extends LimitOrder {
orderInfo: OrderInfoDataFusion,
auctionDetails: AuctionDetails,
postInteractionData: PostInteractionData,
flags: {
extra: {
unwrapWETH?: boolean
/**
* Required if `allowPartialFills` is false
*/
nonce?: bigint
permit?: string
/**
* Default is true
*/
allowPartialFills?: boolean
} = {},
deadline = auctionDetails.auctionStartTime + 120n
/**
* Default deadline is 2m
*/
deadline?: bigint
} = {}
) {
const makerTraits = MakerTraits.default()
.withExpiration(deadline)
.withExpiration(
extra.deadline || auctionDetails.auctionStartTime + 120n
)
.allowMultipleFills()

if (flags.allowPartialFills) {
const allowPartialFills = extra.allowPartialFills ?? true

if (allowPartialFills) {
makerTraits.allowPartialFills()
} else {
makerTraits.disablePartialFills()

assert(
extra.nonce !== undefined,
'Nonce required, when partial fills disabled'
)
}

const unwrapWETH =
flags.unwrapWETH === undefined ? false : flags.unwrapWETH
const unwrapWETH = extra.unwrapWETH ?? false

if (unwrapWETH) {
makerTraits.enableNativeUnwrap()
}

if (flags.nonce !== undefined) {
makerTraits.withNonce(flags.nonce).enableEpochManagerCheck()
if (extra.nonce !== undefined) {
makerTraits.withNonce(extra.nonce)
}

const extensionAddress =
Expand All @@ -56,8 +73,8 @@ export class FusionOrder extends LimitOrder {
postInteractionData
)

if (flags.permit) {
extension.withMakerPermit(orderInfo.makerAsset, flags.permit)
if (extra.permit) {
extension.withMakerPermit(orderInfo.makerAsset, extra.permit)
}

const builtExtension = extension.build()
Expand Down
3 changes: 1 addition & 2 deletions src/limit-order/maker-traits.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ describe('MakerTraits', () => {

test('expiration', () => {
const traits = MakerTraits.default()
const expiration = new Date(Date.now() + 10_000)
expiration.setMilliseconds(0)
const expiration = 1000000n

traits.withExpiration(expiration)
expect(traits.expiration()).toEqual(expiration)
Expand Down
17 changes: 5 additions & 12 deletions src/limit-order/maker-traits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,22 @@ export class MakerTraits {
/**
* If null is return than order has no expiration
*/
public expiration(): Date | null {
public expiration(): bigint | null {
const timestampSec = this.value.getMask(MakerTraits.EXPIRATION_MASK)

if (timestampSec.isZero()) {
return null
}

return new Date(Number(timestampSec.value * 1000n))
return timestampSec.value
}

public withExpiration(expiration: Date | null | bigint): this {
const expirationSec =
expiration === null
? 0
: expiration instanceof Date
? Math.floor(expiration.getTime() / 1000)
: expiration

const timestampSec = BigInt(expirationSec)
public withExpiration(expiration: bigint): this {
const expirationSec = expiration === null ? 0n : expiration

this.value = this.value.setMask(
MakerTraits.EXPIRATION_MASK,
timestampSec
expirationSec
)

return this
Expand Down
1 change: 0 additions & 1 deletion src/nonce-manager/constants.ts

This file was deleted.

31 changes: 0 additions & 31 deletions src/nonce-manager/nonce-manager.spec.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/nonce-manager/nonce-manager.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/nonce-manager/types.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/nonce-manager/utils.ts

This file was deleted.

10 changes: 10 additions & 0 deletions src/utils/bytes/bn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ describe('BN', () => {

expect(bn.clearMask(mask).value).toEqual(0xab001111n)
})

test('setBit', () => {
const bn = new BN(0xab7f1111n)

expect(bn.setBit(0n, 0).value).toEqual(0xab7f1110n)
expect(bn.setBit(4n, 0).value).toEqual(0xab7f1101n)

expect(bn.setBit(1n, 1).value).toEqual(0xab7f1113n)
expect(bn.setBit(5n, 1).value).toEqual(0xab7f1131n)
})
})

0 comments on commit 48a93a3

Please sign in to comment.