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

SDK: add RFQ #1695

Merged
merged 71 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
bb00e65
ChainToken marshalling
ChiTimesChi Dec 21, 2023
35d395e
Ticker marshalling
ChiTimesChi Dec 21, 2023
29f40e5
Chore: docs
ChiTimesChi Dec 21, 2023
b9b5b79
Scaffold FastBridge class
ChiTimesChi Dec 21, 2023
49be732
Scaffold FastBridgeSet class
ChiTimesChi Dec 21, 2023
6f01711
Implement `getBridgeRoutes`
ChiTimesChi Dec 21, 2023
a075c0d
Add some initial values for RFQ contracts
ChiTimesChi Dec 21, 2023
3a5c04c
Add coverage for `createNoSwapQuery`
ChiTimesChi Dec 22, 2023
05c4821
Add fastBridgeContract
ChiTimesChi Dec 22, 2023
3fc3564
Implement `fastBridge.bridge()`
ChiTimesChi Dec 22, 2023
40494b1
Initialize set of FastBridge modules
ChiTimesChi Dec 22, 2023
266b978
FastBridgeQuote type for current Quote structure
ChiTimesChi Dec 23, 2023
740c583
Add `applyQuote()`
ChiTimesChi Dec 23, 2023
a5cd3ad
Adjust getBridgeRoutes to current API
ChiTimesChi Dec 23, 2023
1419de6
Implement `getAllQuotes`
ChiTimesChi Dec 23, 2023
30972c0
Add API unit tests, make SDK tests pass
ChiTimesChi Dec 25, 2023
c232272
Add node-fetch@^2 for integration tests
ChiTimesChi Dec 25, 2023
43e7190
Add URL, integration test
ChiTimesChi Dec 25, 2023
e2e89b2
Add unit tests for quote pricing
ChiTimesChi Dec 27, 2023
601af73
Add some tests around zero quotes
ChiTimesChi Dec 27, 2023
0bca1ab
Hardcode rounding tests
ChiTimesChi Dec 27, 2023
13bf199
Use correct pricing algo
ChiTimesChi Dec 27, 2023
0f38c83
Add tests for FastBridgeSet
ChiTimesChi Dec 28, 2023
fe786cb
Fix: properly implement quote filtering
ChiTimesChi Dec 28, 2023
438dd57
Add some units tests for FastBridge class
ChiTimesChi Dec 28, 2023
c34a918
Mainnet API URL
ChiTimesChi Dec 28, 2023
b5a56bc
Draw the rest of the owl
ChiTimesChi Dec 28, 2023
18b4425
Fix: incorrect invariant
ChiTimesChi Dec 28, 2023
01e23e8
Temp FE fix: don't apply slippage to RFQ
ChiTimesChi Dec 28, 2023
32dcaf6
[DROP IN PROD] Use local SDK for build
ChiTimesChi Dec 28, 2023
b5c0c0b
Add tests for expected `bridge()` behavior
ChiTimesChi Dec 29, 2023
6d9afdb
Use correct tx.value
ChiTimesChi Dec 29, 2023
8fae090
[REVERT IN PROD] up the deadline for RFQ
ChiTimesChi Dec 30, 2023
7949f72
Update FastBridge bindings
ChiTimesChi Jan 2, 2024
4f1dda0
Temp fix: support origin sender address
ChiTimesChi Jan 2, 2024
be79abc
Update FastBridge addresses
ChiTimesChi Jan 2, 2024
77a860a
Use only quotes with age of [0 .. 5) minutes
ChiTimesChi Jan 5, 2024
5276086
Skip tests: sending with non-zero gas rebate
ChiTimesChi Jan 5, 2024
4c46d14
Temp fix for zero gas airdrop for RFQ
ChiTimesChi Jan 5, 2024
fd973fd
Include origin/dest FastBridge address in api response
ChiTimesChi Jan 5, 2024
41c9d46
Discard quotes with non-relevant FastBridge address
ChiTimesChi Jan 5, 2024
9af5cb5
Update addresses
ChiTimesChi Jan 5, 2024
9fade87
Fix: tests
ChiTimesChi Jan 5, 2024
60f8a20
Merge branch 'master' into sdk/add-rfq
aureliusbtc Jan 5, 2024
48157b4
Merge branch 'master' into sdk/add-rfq
aureliusbtc Jan 5, 2024
b821bc9
try to add rfq bridgestatus sdk call to fe
aureliusbtc Jan 6, 2024
2087e02
Fix: use snake case for api quote schema
dwasse Jan 6, 2024
655ee4b
Fix: tests
dwasse Jan 6, 2024
ae4844c
yarn lint:fix
ChiTimesChi Jan 6, 2024
9fa247b
Merge pull request #1747 from synapsecns/sdk/add-rfq-api-schema
ChiTimesChi Jan 6, 2024
032f4c0
Coverage for RFQ tracking
ChiTimesChi Jan 6, 2024
3ec5a76
SDK: fix median time
ChiTimesChi Jan 6, 2024
ad6e838
Start using SDK to check status earlier
ChiTimesChi Jan 6, 2024
2f990a6
Revert "[REVERT IN PROD] up the deadline for RFQ"
ChiTimesChi Jan 6, 2024
4a3b78a
Add bridgeTransactions reducer to host updated Txn flow
bigboydiamonds Jan 7, 2024
6a8fd75
Expose helper hook `useBridgeTransactionsState`
bigboydiamonds Jan 7, 2024
41f7a52
_Transaction component using SDK for status
bigboydiamonds Jan 7, 2024
1645c00
_Transactions component to render individual _Transaction
bigboydiamonds Jan 7, 2024
32f68b1
Implement SDK-based Pending Transaction flow
bigboydiamonds Jan 7, 2024
5c40fca
Persist _Transaction slice
bigboydiamonds Jan 7, 2024
a49e86f
_Transaction tracking newly fired txs
bigboydiamonds Jan 7, 2024
c9eb34c
Provide Origin/Destination Token/Chain into _Transaction
bigboydiamonds Jan 7, 2024
f215684
Basic styled _Transaction component with SDK tracking
bigboydiamonds Jan 7, 2024
1c5af4f
Add spacing between Tx
bigboydiamonds Jan 7, 2024
dffb9f7
Merge branch 'fe/activity-pending-sdk' into sdk/add-rfq
aureliusbtc Jan 7, 2024
d9ae90e
Updated FE transaction time estimation logic and interval check frequ…
aureliusbtc Jan 7, 2024
410ebdb
Adds try catch to prevent app crashing (#1762)
abtestingalpha Jan 7, 2024
b1e6301
Merge branch 'master' into sdk/add-rfq
aureliusbtc Jan 7, 2024
d0e6a01
Fe/sorting wip (#1770)
abtestingalpha Jan 8, 2024
a3c745e
Chore: fix lint
ChiTimesChi Jan 8, 2024
139c512
Revert "[DROP IN PROD] Use local SDK for build"
ChiTimesChi Jan 8, 2024
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
2 changes: 2 additions & 0 deletions packages/sdk-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
"@types/jest": "^24.0.25",
"dotenv": "^16.3.1",
"husky": "^8.0.1",
"jest-mock-extended": "^3.0.5",
"node-fetch": "^2.0.0",
"size-limit": "^8.1.0",
"tsdx": "^0.14.1",
"tslib": "^2.4.0",
Expand Down
1 change: 1 addition & 0 deletions packages/sdk-router/src/abi/FastBridge.json
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@
{
"components": [
{ "internalType": "uint32", "name": "dstChainId", "type": "uint32" },
{ "internalType": "address", "name": "sender", "type": "address" },
{ "internalType": "address", "name": "to", "type": "address" },
{
"internalType": "address",
Expand Down
24 changes: 23 additions & 1 deletion packages/sdk-router/src/constants/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { CCTP_SUPPORTED_CHAIN_IDS, SUPPORTED_CHAIN_IDS } from './chainIds'
import {
CCTP_SUPPORTED_CHAIN_IDS,
RFQ_SUPPORTED_CHAIN_IDS,
SUPPORTED_CHAIN_IDS,
SupportedChainId,
} from './chainIds'

export type AddressMap = {
[chainId: number]: string
Expand Down Expand Up @@ -48,3 +53,20 @@ export const CCTP_ROUTER_ADDRESS_MAP: AddressMap = generateAddressMap(
CCTP_ROUTER_ADDRESS,
CCTP_ROUTER_EXCEPTION_MAP
)

/**
* FastBridge contract address for all chains except ones from FAST_BRIDGE_ADDRESS.
*
* TODO: Update this address once FastBridge is deployed.
*/
const FAST_BRIDGE_ADDRESS = ''
const FAST_BRIDGE_EXCEPTION_MAP: AddressMap = {
Comment on lines +60 to +62
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FAST_BRIDGE_ADDRESS is currently an empty string with a TODO comment to update it once the FastBridge is deployed. Ensure that this placeholder does not cause any issues in the current implementation and that the TODO is addressed before deployment.

[SupportedChainId.OPTIMISM]: '0x743fFbd0DbF88F6fCB7FaDf58fB641da93056EdF',
[SupportedChainId.ARBITRUM]: '0xA9EBFCb6DCD416FE975D5aB862717B329407f4F7',
}

export const FAST_BRIDGE_ADDRESS_MAP: AddressMap = generateAddressMap(
RFQ_SUPPORTED_CHAIN_IDS,
FAST_BRIDGE_ADDRESS,
FAST_BRIDGE_EXCEPTION_MAP
)
10 changes: 10 additions & 0 deletions packages/sdk-router/src/constants/chainIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@ export const CCTP_SUPPORTED_CHAIN_IDS: number[] = [
SupportedChainId.BASE,
SupportedChainId.POLYGON, // Circle domain 7
]

/**
* List of chain ids where FastBridge (RFQ) is deployed, ordered by chain id
*
* Note: This is a subset of SUPPORTED_CHAIN_IDS.
*/
export const RFQ_SUPPORTED_CHAIN_IDS: number[] = [
SupportedChainId.OPTIMISM,
SupportedChainId.ARBITRUM,
]
10 changes: 10 additions & 0 deletions packages/sdk-router/src/constants/medianTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ export const MEDIAN_TIME_CCTP = {
[SupportedChainId.AVALANCHE]: 30,
[SupportedChainId.POLYGON]: 480,
}

/**
* Median time (in seconds) for a SynapseRFQ transaction to be completed,
* when the transaction is sent from a given chain.
* TODO: Update this value once we have a better estimate.
*/
export const MEDIAN_TIME_RFQ = {
[SupportedChainId.OPTIMISM]: 30,
[SupportedChainId.ARBITRUM]: 30,
}
12 changes: 12 additions & 0 deletions packages/sdk-router/src/module/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
modifyDeadline,
applySlippage,
applySlippageInBips,
createNoSwapQuery,
} from './query'

describe('#query', () => {
Expand Down Expand Up @@ -380,4 +381,15 @@ describe('#query', () => {
)
})
})

it('createNoSwapQuery', () => {
const query = createNoSwapQuery('1', BigNumber.from(2))
expect(query).toEqual({
routerAdapter: '0x0000000000000000000000000000000000000000',
tokenOut: '1',
minAmountOut: BigNumber.from(2),
deadline: BigNumber.from(0),
rawParams: '0x',
})
})
})
17 changes: 17 additions & 0 deletions packages/sdk-router/src/module/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,20 @@ export const applySlippageInBips = (
): Query => {
return applySlippage(query, slipBasisPoints, 10000)
}

/**
* Creates a Query object for a no-swap bridge action.
*
* @param token - The token to bridge.
* @param amount - The amount of token to bridge.
* @returns The Query object for a no-swap bridge action.
*/
export const createNoSwapQuery = (token: string, amount: BigNumber): Query => {
return {
routerAdapter: AddressZero,
tokenOut: token,
minAmountOut: amount,
deadline: BigNumber.from(0),
rawParams: '0x',
}
}
69 changes: 69 additions & 0 deletions packages/sdk-router/src/rfq/api.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { getAllQuotes } from './api'
import { FastBridgeQuoteAPI, unmarshallFastBridgeQuote } from './quote'

describe('getAllQuotes', () => {
const quotesAPI: FastBridgeQuoteAPI[] = [
{
origin_chain_id: 1,
origin_token_addr: '0x0000000000000000000000000000000000000001',
dest_chain_id: 2,
dest_token_addr: '0x0000000000000000000000000000000000000002',
dest_amount: '3',
max_origin_amount: '4',
fixed_fee: '5',
origin_fast_bridge_address: '10',
dest_fast_bridge_address: '11',
relayer_addr: '0x0000000000000000000000000000000000000003',
updated_at: '2023-01-01T00:00:00.420Z',
},
{
origin_chain_id: 3,
origin_token_addr: '0x0000000000000000000000000000000000000004',
dest_chain_id: 4,
dest_token_addr: '0x0000000000000000000000000000000000000005',
dest_amount: '6',
max_origin_amount: '7',
fixed_fee: '8',
origin_fast_bridge_address: '20',
dest_fast_bridge_address: '21',
relayer_addr: '0x0000000000000000000000000000000000000006',
updated_at: '2023-01-02T00:00:00.420Z',
},
]

it('returns an empty array when the response is not ok', async () => {
global.fetch = jest.fn(() =>
Promise.resolve({
status: 500,
ok: false,
})
) as any

const result = await getAllQuotes()
expect(result).toEqual([])
})

it('returns a list of quotes when the response is ok', async () => {
global.fetch = jest.fn(() =>
Promise.resolve({
status: 200,
ok: true,
json: () => Promise.resolve(quotesAPI),
})
) as any

const result = await getAllQuotes()
// You might need to adjust this depending on how your unmarshallFastBridgeQuote function works
expect(result).toEqual([
unmarshallFastBridgeQuote(quotesAPI[0]),
unmarshallFastBridgeQuote(quotesAPI[1]),
])
})

it('Integration test', async () => {
global.fetch = require('node-fetch')
const result = await getAllQuotes()
console.log('Quotes: ' + JSON.stringify(result, null, 2))
expect(result.length).toBeGreaterThan(0)
})
Comment on lines +63 to +68
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The integration test now includes an assertion for the result length, which is an improvement over the previous use of console.log. However, consider adding more detailed assertions to validate the structure and content of the returned quotes.

- console.log('Quotes: ' + JSON.stringify(result, null, 2))
+ // Additional structure and content checks can be added here

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
it('Integration test', async () => {
global.fetch = require('node-fetch')
const result = await getAllQuotes()
console.log('Quotes: ' + JSON.stringify(result, null, 2))
expect(result.length).toBeGreaterThan(0)
})
it('Integration test', async () => {
global.fetch = require('node-fetch')
const result = await getAllQuotes()
// Additional structure and content checks can be added here
expect(result.length).toBeGreaterThan(0)
})

})
23 changes: 23 additions & 0 deletions packages/sdk-router/src/rfq/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
FastBridgeQuote,
FastBridgeQuoteAPI,
unmarshallFastBridgeQuote,
} from './quote'

const API_URL = 'https://rfq-api.omnirpc.io'

/**
* Hits Quoter API /quotes endpoint to get all quotes.
*
* @returns A promise that resolves to the list of quotes.
*/
export const getAllQuotes = async (): Promise<FastBridgeQuote[]> => {
const response = await fetch(API_URL + '/quotes')
// Return empty list if response is not ok
if (!response.ok) {
return []
}
// The response is a list of quotes in the FastBridgeQuoteAPI format
const quotes: FastBridgeQuoteAPI[] = await response.json()
return quotes.map(unmarshallFastBridgeQuote)
}
Loading
Loading