Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): use v2 version #86

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/api/orders/order-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe(__filename, () => {

expect(response).toEqual(expected)
expect(httpProvider.get).toHaveBeenLastCalledWith(
`${url}/orders/v1.0/1/order/active/?page=1&limit=2`
`${url}/orders/v2.0/1/order/active/?page=1&limit=2`
)
})

Expand Down Expand Up @@ -175,7 +175,7 @@ describe(__filename, () => {

expect(response).toEqual(expected)
expect(httpProvider.get).toHaveBeenLastCalledWith(
`${url}/orders/v1.0/1/order/active/?`
`${url}/orders/v2.0/1/order/active/?`
)
})
})
Expand Down Expand Up @@ -225,7 +225,7 @@ describe(__filename, () => {

expect(response).toEqual(expected)
expect(httpProvider.get).toHaveBeenLastCalledWith(
`${url}/orders/v1.0/1/order/status/${orderHash}`
`${url}/orders/v2.0/1/order/status/${orderHash}`
)
})

Expand Down Expand Up @@ -377,7 +377,7 @@ describe(__filename, () => {

expect(response).toEqual(expected)
expect(httpProvider.get).toHaveBeenLastCalledWith(
`${url}/orders/v1.0/1/order/maker/${address}/?limit=1&page=1`
`${url}/orders/v2.0/1/order/maker/${address}/?limit=1&page=1`
)
})

Expand Down Expand Up @@ -433,7 +433,7 @@ describe(__filename, () => {

expect(response).toEqual(expected)
expect(httpProvider.get).toHaveBeenLastCalledWith(
`${url}/orders/v1.0/1/order/maker/${address}/?`
`${url}/orders/v2.0/1/order/maker/${address}/?`
)
})

Expand Down
8 changes: 5 additions & 3 deletions src/api/orders/orders.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {AxiosProviderConnector, HttpProviderConnector} from '../../connector'
import {concatQueryParams} from '../params'

export class OrdersApi {
private static Version = 'v2.0'

constructor(
private readonly config: OrdersApiConfig,
private readonly httpClient: HttpProviderConnector
Expand All @@ -37,7 +39,7 @@ export class OrdersApi {
}

const queryParams = concatQueryParams(params.build())
const url = `${this.config.url}/v1.0/${this.config.network}/order/active/${queryParams}`
const url = `${this.config.url}/${OrdersApi.Version}/${this.config.network}/order/active/${queryParams}`

return this.httpClient.get<ActiveOrdersResponse>(url)
}
Expand All @@ -51,7 +53,7 @@ export class OrdersApi {
throw new Error(err)
}

const url = `${this.config.url}/v1.0/${this.config.network}/order/status/${params.orderHash}`
const url = `${this.config.url}/${OrdersApi.Version}/${this.config.network}/order/status/${params.orderHash}`

return this.httpClient.get<OrderStatusResponse>(url)
}
Expand All @@ -66,7 +68,7 @@ export class OrdersApi {
}

const queryParams = concatQueryParams(params.buildQueryParams())
const url = `${this.config.url}/v1.0/${this.config.network}/order/maker/${params.address}/${queryParams}`
const url = `${this.config.url}/${OrdersApi.Version}/${this.config.network}/order/maker/${params.address}/${queryParams}`

return this.httpClient.get(url)
}
Expand Down
21 changes: 15 additions & 6 deletions src/api/quoter/quote/quote.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Address} from '@1inch/limit-order-sdk'
import {Address, randBigInt} from '@1inch/limit-order-sdk'
import {UINT_40_MAX} from '@1inch/byte-utils'
import {FusionOrderParams} from './order-params'
import {FusionOrderParamsData} from './types'
import {Cost, PresetEnum, QuoterResponse} from '../types'
Expand Down Expand Up @@ -76,6 +77,16 @@ export class Quote {
params.delayAuctionStartTimeBy
)

const allowPartialFills =
paramsData?.allowPartialFills ?? preset.allowPartialFills
const allowMultipleFills =
paramsData?.allowMultipleFills ?? preset.allowMultipleFills
const isNonceRequired = !allowPartialFills || !allowMultipleFills

const nonce = isNonceRequired
? params.nonce ?? randBigInt(UINT_40_MAX)
: params.nonce

return FusionOrder.new(
this.settlementAddress,
{
Expand Down Expand Up @@ -103,15 +114,13 @@ export class Quote {
)
},
{
nonce: params.nonce,
nonce,
unwrapWETH: this.params.toTokenAddress.isNative(),
permit: params.permit
? this.params.fromTokenAddress + params.permit.substring(2)
: undefined,
allowPartialFills:
paramsData?.allowPartialFills ?? preset.allowPartialFills,
allowMultipleFills:
paramsData?.allowMultipleFills ?? preset.allowMultipleFills,
allowPartialFills,
allowMultipleFills,
orderExpirationDelay: paramsData?.orderExpirationDelay
}
)
Expand Down
6 changes: 3 additions & 3 deletions src/api/quoter/quoter.api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('Quoter API', () => {

expect(res).toStrictEqual(QuoterResponseMock)
expect(httpProvider.get).toHaveBeenCalledWith(
'https://test.com/quoter/v1.0/1/quote/receive/?fromTokenAddress=0x6b175474e89094c44da98b954eedeac495271d0f&toTokenAddress=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2&amount=1000000000000000000000&walletAddress=0x00000000219ab540356cbb839cbe05303d7705fa&source=sdk'
'https://test.com/quoter/v2.0/1/quote/receive/?fromTokenAddress=0x6b175474e89094c44da98b954eedeac495271d0f&toTokenAddress=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2&amount=1000000000000000000000&walletAddress=0x00000000219ab540356cbb839cbe05303d7705fa&source=sdk'
)
})

Expand All @@ -161,7 +161,7 @@ describe('Quoter API', () => {
const res = await quoter.getQuote(params)
expect(res).toStrictEqual(QuoterResponseMock)
expect(httpProvider.get).toHaveBeenCalledWith(
'https://test.com/quoter/v1.0/1/quote/receive/?fromTokenAddress=0x6b175474e89094c44da98b954eedeac495271d0f&toTokenAddress=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2&amount=1000000000000000000000&walletAddress=0x00000000219ab540356cbb839cbe05303d7705fa&fee=1&source=0x6b175474e89094c44da98b954eedeac495271d0f'
'https://test.com/quoter/v2.0/1/quote/receive/?fromTokenAddress=0x6b175474e89094c44da98b954eedeac495271d0f&toTokenAddress=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2&amount=1000000000000000000000&walletAddress=0x00000000219ab540356cbb839cbe05303d7705fa&fee=1&source=0x6b175474e89094c44da98b954eedeac495271d0f'
)
})

Expand Down Expand Up @@ -199,7 +199,7 @@ describe('Quoter API', () => {
const res = await quoter.getQuoteWithCustomPreset(params, body)
expect(res).toStrictEqual(QuoterResponseMock)
expect(httpProvider.post).toHaveBeenCalledWith(
'https://test.com/quoter/v1.0/1/quote/receive/?fromTokenAddress=0x6b175474e89094c44da98b954eedeac495271d0f&toTokenAddress=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2&amount=1000000000000000000000&walletAddress=0x00000000219ab540356cbb839cbe05303d7705fa&fee=1&source=0x6b175474e89094c44da98b954eedeac495271d0f',
'https://test.com/quoter/v2.0/1/quote/receive/?fromTokenAddress=0x6b175474e89094c44da98b954eedeac495271d0f&toTokenAddress=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2&amount=1000000000000000000000&walletAddress=0x00000000219ab540356cbb839cbe05303d7705fa&fee=1&source=0x6b175474e89094c44da98b954eedeac495271d0f',
body.build()
)
})
Expand Down
6 changes: 4 additions & 2 deletions src/api/quoter/quoter.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {concatQueryParams} from '../params'
import {AxiosProviderConnector, HttpProviderConnector} from '../../connector'

export class QuoterApi {
private static Version = 'v2.0'

constructor(
private readonly config: QuoterApiConfig,
private readonly httpClient: HttpProviderConnector
Expand All @@ -22,7 +24,7 @@ export class QuoterApi {

async getQuote(params: QuoterRequest): Promise<Quote> {
const queryParams = concatQueryParams(params.build())
const url = `${this.config.url}/v1.0/${this.config.network}/quote/receive/${queryParams}`
const url = `${this.config.url}/${QuoterApi.Version}/${this.config.network}/quote/receive/${queryParams}`

const res = await this.httpClient.get<QuoterResponse>(url)

Expand All @@ -41,7 +43,7 @@ export class QuoterApi {

const queryParams = concatQueryParams(params.build())
const bodyParams = body.build()
const url = `${this.config.url}/v1.0/${this.config.network}/quote/receive/${queryParams}`
const url = `${this.config.url}/${QuoterApi.Version}/${this.config.network}/quote/receive/${queryParams}`

const res = await this.httpClient.post<QuoterResponse>(url, bodyParams)

Expand Down
13 changes: 8 additions & 5 deletions src/api/relayer/relayer.api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ describe('Relayer API', () => {
makerTraits: '0'
},
signature: '0x123signature-here789',
quoteId: '9a43c86d-f3d7-45b9-8cb6-803d2bdfa08b'
quoteId: '9a43c86d-f3d7-45b9-8cb6-803d2bdfa08b',
extension: '0x'
}

const params = RelayerRequest.new(orderData)

await quoter.submit(params)

expect(httpProvider.post).toHaveBeenCalledWith(
'https://test.com/relayer/v1.0/1/order/submit',
'https://test.com/relayer/v2.0/1/order/submit',
orderData
)
})
Expand All @@ -68,7 +69,8 @@ describe('Relayer API', () => {
makerTraits: '0'
},
signature: '0x123signature-here789',
quoteId: '9a43c86d-f3d7-45b9-8cb6-803d2bdfa08b'
quoteId: '9a43c86d-f3d7-45b9-8cb6-803d2bdfa08b',
extension: '0x'
}

const orderData2: RelayerRequestParams = {
Expand All @@ -83,7 +85,8 @@ describe('Relayer API', () => {
makerTraits: '0'
},
signature: '0x123signature-2-here789',
quoteId: '1a36c861-ffd7-45b9-1cb6-403d3bdfa084'
quoteId: '1a36c861-ffd7-45b9-1cb6-403d3bdfa084',
extension: '0x'
}

const params = [
Expand All @@ -94,7 +97,7 @@ describe('Relayer API', () => {
await quoter.submitBatch(params)

expect(httpProvider.post).toHaveBeenCalledWith(
'https://test.com/relayer/v1.0/1/order/submit/many',
'https://test.com/relayer/v2.0/1/order/submit/many',
params
)
})
Expand Down
6 changes: 4 additions & 2 deletions src/api/relayer/relayer.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {RelayerApiConfig} from './types'
import {AxiosProviderConnector, HttpProviderConnector} from '../../connector'

export class RelayerApi {
private static Version = 'v2.0'

constructor(
private readonly config: RelayerApiConfig,
private readonly httpClient: HttpProviderConnector
Expand All @@ -18,13 +20,13 @@ export class RelayerApi {
}

submit(params: RelayerRequest): Promise<void> {
const url = `${this.config.url}/v1.0/${this.config.network}/order/submit`
const url = `${this.config.url}/${RelayerApi.Version}/${this.config.network}/order/submit`

return this.httpClient.post(url, params)
}

submitBatch(params: RelayerRequest[]): Promise<void> {
const url = `${this.config.url}/v1.0/${this.config.network}/order/submit/many`
const url = `${this.config.url}/${RelayerApi.Version}/${this.config.network}/order/submit/many`

return this.httpClient.post(url, params)
}
Expand Down
6 changes: 5 additions & 1 deletion src/api/relayer/relayer.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ export class RelayerRequest {

public readonly quoteId: string

public readonly extension: string

constructor(params: RelayerRequestParams) {
this.order = params.order
this.signature = params.signature
this.quoteId = params.quoteId
this.extension = params.extension
}

static new(params: RelayerRequestParams): RelayerRequest {
Expand All @@ -22,7 +25,8 @@ export class RelayerRequest {
return {
order: this.order,
signature: this.signature,
quoteId: this.quoteId
quoteId: this.quoteId,
extension: this.extension
}
}
}
1 change: 1 addition & 0 deletions src/api/relayer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type RelayerRequestParams = {
order: LimitOrderV4Struct
signature: string
quoteId: string
extension: string
}

export type RelayerApiConfig = {
Expand Down
5 changes: 3 additions & 2 deletions src/fusion-order/fusion-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class FusionOrder {
extra: {
unwrapWETH?: boolean
/**
* Required if `allowPartialFills` is false
* Required if `allowPartialFills` or `allowMultipleFills` is false
*/
nonce?: bigint
/**
Expand Down Expand Up @@ -230,7 +230,8 @@ export class FusionOrder {
extra?: {
unwrapWETH?: boolean
/**
* Required if `allowPartialFills` is false
* Required if `allowPartialFills` or `allowMultipleFills` is false
* Max size is 40bit
*/
nonce?: bigint
permit?: string
Expand Down
6 changes: 4 additions & 2 deletions src/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ export class FusionSDK {
const relayerRequest = RelayerRequest.new({
order: orderStruct,
signature,
quoteId
quoteId,
extension: order.extension.encode()
})

await this.api.submitOrder(relayerRequest)
Expand All @@ -151,7 +152,8 @@ export class FusionSDK {
order: orderStruct,
signature,
quoteId,
orderHash: order.getOrderHash(this.config.network)
orderHash: order.getOrderHash(this.config.network),
extension: relayerRequest.extension
}
}

Expand Down
1 change: 1 addition & 0 deletions src/sdk/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export type OrderInfo = {
signature: string
quoteId: string
orderHash: string
extension: string
}

export type PreparedOrder = {
Expand Down
2 changes: 1 addition & 1 deletion src/ws-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MyFancyProvider implements WsProviderConnector {
// ... user implementation
}

const url = 'wss://api.1inch.dev/fusion/ws/v1.0/1'
const url = 'wss://api.1inch.dev/fusion/ws/v2.0/1'
const provider = new MyFancyProvider({url})

const wsSdk = new WebSocketApi(provider)
Expand Down
4 changes: 3 additions & 1 deletion src/ws-api/ws-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
} from '../connector/ws'

export class WebSocketApi {
private static Version = 'v2.0'

public readonly rpc: RpcWebsocketApi

public readonly order: ActiveOrdersWebSocketApi
Expand All @@ -22,7 +24,7 @@ export class WebSocketApi {
) {
if (instanceOfWsApiConfigWithNetwork(configOrProvider)) {
const url = castUrl(configOrProvider.url)
const urlWithNetwork = `${url}/v1.0/${configOrProvider.network}`
const urlWithNetwork = `${url}/${WebSocketApi.Version}/${configOrProvider.network}`
const configWithUrl = {...configOrProvider, url: urlWithNetwork}
const provider = new WebsocketClient(configWithUrl)

Expand Down
Loading
Loading