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

feat(sdk): uuid BridgeQuote.id #2896

Merged
merged 14 commits into from
Aug 26, 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
8 changes: 8 additions & 0 deletions packages/sdk-router/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
module.exports = {
maxConcurrency: 1,
testTimeout: 30000,
moduleNameMapper: {
/**
* Force module uuidv7 to resolve with the CJS entry point,
* because Jest does not support package.json.exports.
* See https://github.com/uuidjs/uuid/issues/451
*/
uuidv7: require.resolve('uuidv7'),
},
}
7 changes: 5 additions & 2 deletions packages/sdk-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,24 @@
},
"dependencies": {
"@babel/core": "^7.20.12",
"@babel/plugin-transform-modules-commonjs": "^7.24.8",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/address": "^5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/constants": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"babel-jest": "^29.4.1",
"babel-jest": "^25.2.6",
"big.js": "^5.2.2",
"decimal.js-light": "^2.5.1",
"ethers": "^5.7.2",
"jest": "^29.7.0",
"jsbi": "^4.3.0",
"node-cache": "^5.1.2",
"tiny-invariant": "^1.2.0",
"toformat": "^2.0.0",
"ts-xor": "^1.1.0"
"ts-xor": "^1.1.0",
"uuidv7": "^1.0.1"
}
}
3 changes: 3 additions & 0 deletions packages/sdk-router/src/module/synapseModuleSet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BigNumber } from '@ethersproject/bignumber'
import { uuidv7 } from 'uuidv7'
import invariant from 'tiny-invariant'

import { BigintIsh } from '../constants'
Expand Down Expand Up @@ -201,13 +202,15 @@ export abstract class SynapseModuleSet {
bridgeRoute.bridgeModuleName === this.bridgeModuleName,
'Invalid bridge module name'
)
const uuid = uuidv7()
const { originQuery, destQuery } = bridgeRoute
const { originModuleDeadline, destModuleDeadline } =
this.getModuleDeadlines(originDeadline, destDeadline)
originQuery.deadline = originModuleDeadline
destQuery.deadline = destModuleDeadline
const { feeAmount, feeConfig } = await this.getFeeData(bridgeRoute)
return {
id: uuid,
feeAmount,
feeConfig,
routerAddress: originModule.address,
Expand Down
1 change: 1 addition & 0 deletions packages/sdk-router/src/module/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type SwapQuote = {
* Returned by SDK to the consumer.
*/
export type BridgeQuote = {
id: string
feeAmount: BigNumber
feeConfig: FeeConfig
routerAddress: string
Expand Down
30 changes: 30 additions & 0 deletions packages/sdk-router/src/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ const createBridgeQuoteTests = (
result = await resultPromise
})

it('Generates a bridge quote with valid uuid', async () => {
expect(typeof result.id).toBe('string')
})

it('Fetches a bridge quote', async () => {
expectCorrectBridgeQuote(result)
})
Expand Down Expand Up @@ -402,6 +406,14 @@ describe('SynapseSDK', () => {
amount
)

const secondResultPromise: Promise<BridgeQuote> = synapse.bridgeQuote(
SupportedChainId.ARBITRUM,
SupportedChainId.ETH,
ARB_USDC,
ETH_USDC,
amount
)

createBridgeQuoteTests(
synapse,
SupportedChainId.ARBITRUM,
Expand Down Expand Up @@ -429,6 +441,13 @@ describe('SynapseSDK', () => {
expect(result.originChainId).toEqual(SupportedChainId.ARBITRUM)
expect(result.destChainId).toEqual(SupportedChainId.ETH)
})

it('Fetches a second Synapse bridge quote with a different ID', async () => {
const firstQuote = await resultPromise
const secondQuote = await secondResultPromise

expect(firstQuote.id).not.toEqual(secondQuote.id)
})
})

describe('ARB USDC -> ETH USDC (using CCTP)', () => {
Expand Down Expand Up @@ -807,6 +826,17 @@ describe('SynapseSDK', () => {
expect(allQuotes[1].destChainId).toEqual(SupportedChainId.ARBITRUM)
})

it('Generates unique IDs for SynapseBridge and SynapseCCTP quotes for USDC', async () => {
const allQuotes = await synapse.allBridgeQuotes(
SupportedChainId.ETH,
SupportedChainId.ARBITRUM,
ETH_USDC,
ARB_USDT,
BigNumber.from(10).pow(9)
)
expect(allQuotes[0].id).not.toEqual(allQuotes[1].id)
})

it('Fetches only SynapseBridge quotes for ETH', async () => {
const allQuotes = await synapse.allBridgeQuotes(
SupportedChainId.ETH,
Expand Down
Loading
Loading