Skip to content

Commit

Permalink
feat(orders-api): add getPublishedSecrets endpoint (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
krboktv committed Aug 22, 2024
1 parent 99e2174 commit 4d4eb77
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/api/fusion-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
OrderStatusRequest,
OrderStatusResponse,
OrdersByMakerResponse,
ReadyToAcceptSecretFills
ReadyToAcceptSecretFills,
PublishedSecretsResponse
} from './orders'

export class FusionApi {
Expand Down Expand Up @@ -86,6 +87,10 @@ export class FusionApi {
return this.ordersApi.getReadyToAcceptSecretFills(orderHash)
}

getPublishedSecrets(orderHash: string): Promise<PublishedSecretsResponse> {
return this.ordersApi.getPublishedSecrets(orderHash)
}

submitOrder(params: RelayerRequest): Promise<void> {
return this.relayerApi.submit(params)
}
Expand Down
29 changes: 29 additions & 0 deletions src/api/orders/order-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
OrdersByMakerResponse,
OrderStatus,
OrderStatusResponse,
OrderType,
PublishedSecretsResponse,
ReadyToAcceptSecretFills,
ValidationStatus
} from './types'
Expand Down Expand Up @@ -565,4 +567,31 @@ describe(__filename, () => {
)
})
})

describe('getPublishedSecrets', () => {
it('success', async () => {
const url = 'https://test.com/orders'

const expected: PublishedSecretsResponse = {
orderType: OrderType.SingleFill,
secrets: []
}
const httpProvider = createHttpProviderFake(expected)
const api = new OrdersApi(
{
url
},
httpProvider
)

const orderHash =
'0x035b5c86d29c154e1e677ef1237de6792ff18d5c92964222ee768c77148e0fb7'
const response = await api.getPublishedSecrets(orderHash)

expect(response).toEqual(expected)
expect(httpProvider.get).toHaveBeenLastCalledWith(
`${url}/v1.0/order/secrets/${orderHash}`
)
})
})
})
9 changes: 9 additions & 0 deletions src/api/orders/orders.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
OrdersApiConfig,
OrdersByMakerResponse,
OrderStatusResponse,
PublishedSecretsResponse,
ReadyToAcceptSecretFills
} from './types'
import {concatQueryParams} from '../params'
Expand Down Expand Up @@ -54,4 +55,12 @@ export class OrdersApi {

return this.httpClient.get(url)
}

async getPublishedSecrets(
orderHash: string
): Promise<PublishedSecretsResponse> {
const url = `${this.config.url}/${OrdersApi.Version}/order/secrets/${orderHash}`

return this.httpClient.get(url)
}
}
32 changes: 32 additions & 0 deletions src/api/orders/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,35 @@ export type ReadyToAcceptSecretFill = {
export type ReadyToAcceptSecretFills = {
fills: ReadyToAcceptSecretFill[]
}

export enum OrderType {
SingleFill = 'SingleFill',
MultipleFills = 'MultipleFills'
}

export type ChainImmutables = {
orderHash: string
hashlock: string
maker: string
taker: string
token: string
amount: string
safetyDeposit: string
timelocks: string
}

export type PublicSecret = {
idx: number
secret: string
srcImmutables: ChainImmutables
dstImmutables: ChainImmutables
}

export type PublishedSecretsResponse = {
orderType: OrderType
secrets: PublicSecret[]

// empty for OrderType.SingleFill
merkleLeaves?: string[]
secretHashes?: string[]
}
9 changes: 8 additions & 1 deletion src/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
OrdersByMakerResponse,
OrderStatusRequest,
OrderStatusResponse,
ReadyToAcceptSecretFills
ReadyToAcceptSecretFills,
PublishedSecretsResponse
} from '../api'
import {CrossChainOrder} from '../cross-chain-order'
import {SupportedChain} from '../chains'
Expand Down Expand Up @@ -65,6 +66,12 @@ export class SDK {
return this.api.getReadyToAcceptSecretFills(orderHash)
}

async getPublishedSecrets(
orderHash: string
): Promise<PublishedSecretsResponse> {
return this.api.getPublishedSecrets(orderHash)
}

async submitSecret(orderHash: string, secret: string): Promise<void> {
return this.api.submitSecret(orderHash, secret)
}
Expand Down

0 comments on commit 4d4eb77

Please sign in to comment.