Skip to content

Commit

Permalink
Storage to Indexing (#1238)
Browse files Browse the repository at this point in the history
* storage to indexing

* update fn signatures, order filter types

* update getOrder args on Server
  • Loading branch information
dmosites authored Dec 19, 2023
1 parent e0be97b commit 6b76cbf
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 67 deletions.
4 changes: 2 additions & 2 deletions source/balances/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"@openzeppelin/contracts": "^4.8.3"
},
"devDependencies": {
"@airswap/constants": "4.1.6",
"@airswap/utils": "4.1.9",
"@airswap/constants": "4.1.7",
"@airswap/utils": "4.1.10",
"prompt-confirm": "^2.0.4"
},
"publishConfig": {
Expand Down
8 changes: 4 additions & 4 deletions source/pool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
"@openzeppelin/contracts": "^4.8.3"
},
"devDependencies": {
"@airswap/constants": "4.1.6",
"@airswap/metadata": "4.1.12",
"@airswap/types": "4.1.1",
"@airswap/utils": "4.1.9",
"@airswap/constants": "4.1.7",
"@airswap/metadata": "4.1.13",
"@airswap/types": "4.1.2",
"@airswap/utils": "4.1.10",
"prompt-confirm": "^2.0.4"
},
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions source/registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"access": "public"
},
"devDependencies": {
"@airswap/constants": "4.1.6",
"@airswap/utils": "4.1.9",
"@airswap/constants": "4.1.7",
"@airswap/utils": "4.1.10",
"prompt-confirm": "^2.0.4"
}
}
2 changes: 1 addition & 1 deletion source/staking/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"access": "public"
},
"devDependencies": {
"@airswap/utils": "4.1.9",
"@airswap/utils": "4.1.10",
"prompt-confirm": "^2.0.4"
}
}
6 changes: 3 additions & 3 deletions source/swap-erc20/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"@openzeppelin/contracts": "^4.8.3"
},
"devDependencies": {
"@airswap/constants": "4.1.6",
"@airswap/constants": "4.1.7",
"@airswap/staking": "4.0.5",
"@airswap/types": "4.1.1",
"@airswap/utils": "4.1.9",
"@airswap/types": "4.1.2",
"@airswap/utils": "4.1.10",
"prompt-confirm": "^2.0.4"
},
"publishConfig": {
Expand Down
6 changes: 3 additions & 3 deletions source/swap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
"@openzeppelin/contracts": "^4.8.3"
},
"devDependencies": {
"@airswap/constants": "4.1.6",
"@airswap/types": "4.1.1",
"@airswap/utils": "4.1.9",
"@airswap/constants": "4.1.7",
"@airswap/types": "4.1.2",
"@airswap/utils": "4.1.10",
"@nomicfoundation/hardhat-network-helpers": "^1.0.7"
},
"publishConfig": {
Expand Down
6 changes: 3 additions & 3 deletions source/wrapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
"@openzeppelin/contracts": "^4.8.3"
},
"devDependencies": {
"@airswap/constants": "4.1.6",
"@airswap/utils": "4.1.9",
"@airswap/types": "4.1.1",
"@airswap/constants": "4.1.7",
"@airswap/utils": "4.1.10",
"@airswap/types": "4.1.2",
"@uniswap/v2-periphery": "^1.1.0-beta.0",
"prompt-confirm": "^2.0.4"
},
Expand Down
16 changes: 8 additions & 8 deletions tools/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ export enum Protocols {
Discovery = '0xf3713ede',
RequestForQuoteERC20 = '0x02ad05d3',
LastLookERC20 = '0x395ca9f1',
StorageERC20 = '0xfdd616a7',
Storage = '0xd8b0f31f',
IndexingERC20 = '0xaf0c1ff7',
Indexing = '0x6d401808',
}

export const protocolInterfaces: Record<string, string[]> = {
Expand All @@ -252,22 +252,22 @@ export const protocolInterfaces: Record<string, string[]> = {
'function setPricingERC20(array(string baseToken,string quoteToken,string minimum,array(array((string level,string price))),array(array((string level,string price)))))',
'function considerOrderERC20(string chainId,string swapContractAddress,string nonce,string expiry,string signerWallet,string signerToken,string signerAmount,string senderToken,string senderAmount,string v,string r,string s)',
],
[Protocols.StorageERC20]: [
[Protocols.IndexingERC20]: [
'function addOrderERC20(string chainId,string swapContractAddress,string nonce,string expiry,string signerWallet,string signerToken,string signerAmount,string senderToken,string senderAmount,string v,string r,string s)',
'function getOrdersERC20((string signerWallet,array(string signerToken),string signerMinAmount,string signerMaxAmount,string senderWallet,array(string senderToken),string senderMinAmount,string senderMaxAmount,string sortField,string sortOrder,string offset,string limit))',
'function getOrdersERC20((string chainId,string signerWallet,string signerToken,string senderWallet,string senderToken),string sortField,string sortOrder,string offset,string limit)',
],
[Protocols.Storage]: [
[Protocols.Indexing]: [
'function addOrder(string chainId,string swapContractAddress,uint256 nonce,uint256 expiry,uint256 protocolFee,(address wallet,address token,bytes4 kind,uint256 id,uint256 amount),(address wallet,address token,bytes4 kind,uint256 id,uint256 amount),address affiliateWallet,uint256 affiliateAmount)',
'function getOrders((string signerWallet,array(string signerToken),string signerMinAmount,string signerMaxAmount,string senderWallet,array(string senderToken),string senderMinAmount,string senderMaxAmount,string sortField,string sortOrder,string offset,string limit))',
'function getOrders((string chainId,string signerWallet,string signerToken,string signerId,string senderWallet,string senderToken),string sortField,string sortOrder,string offset,string limit)',
],
}

export const protocolNames: Record<string, string> = {
[Protocols.Discovery]: 'Discovery',
[Protocols.RequestForQuoteERC20]: 'Request for Quote (ERC20)',
[Protocols.LastLookERC20]: 'Last Look (ERC20)',
[Protocols.StorageERC20]: 'Storage (ERC20)',
[Protocols.Storage]: 'Storage',
[Protocols.IndexingERC20]: 'Indexing (ERC20)',
[Protocols.Indexing]: 'Indexing',
}

export enum TokenKinds {
Expand Down
2 changes: 1 addition & 1 deletion tools/constants/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airswap/constants",
"version": "4.1.6",
"version": "4.1.7",
"description": "AirSwap: Constants for Developers",
"repository": {
"type": "git",
Expand Down
8 changes: 4 additions & 4 deletions tools/libraries/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airswap/libraries",
"version": "4.1.14",
"version": "4.1.15",
"description": "AirSwap: Libraries for Developers",
"repository": {
"type": "git",
Expand All @@ -27,15 +27,15 @@
},
"dependencies": {
"@airswap/balances": "4.0.4",
"@airswap/constants": "4.1.6",
"@airswap/constants": "4.1.7",
"@airswap/jsonrpc-client-websocket": "0.0.1",
"@airswap/registry": "4.1.3",
"@airswap/pool": "4.1.4",
"@airswap/staking": "4.0.5",
"@airswap/swap": "4.1.2",
"@airswap/swap-erc20": "4.1.6",
"@airswap/types": "4.1.1",
"@airswap/utils": "4.1.9",
"@airswap/types": "4.1.2",
"@airswap/utils": "4.1.10",
"@airswap/wrapper": "4.1.5",
"browser-or-node": "^2.1.1",
"ethers": "^5.6.9",
Expand Down
24 changes: 20 additions & 4 deletions tools/libraries/src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export class Server extends TypedEmitter<ServerEvents> {
}

/**
* Protocols.StorageERC20
* Protocols.IndexingERC20
*/
public async addOrderERC20(
fullOrder: FullOrderERC20
Expand All @@ -344,12 +344,20 @@ export class Server extends TypedEmitter<ServerEvents> {
}

public async getOrdersERC20(
orderFilter: OrderFilter
orderFilter: OrderFilter,
offset: number,
limit: number,
sortField?: SortField,
sortOrder?: SortOrder
): Promise<OrderResponse<FullOrderERC20>> {
try {
return Promise.resolve(
(await this.httpCall('getOrdersERC20', [
{ ...this.toBigIntJson(orderFilter) },
offset,
limit,
sortField,
sortOrder,
])) as OrderResponse<FullOrderERC20>
)
} catch (err) {
Expand All @@ -358,7 +366,7 @@ export class Server extends TypedEmitter<ServerEvents> {
}

/**
* Protocols.Storage
* Protocols.Indexing
*/
public async addOrder(order: FullOrder): Promise<SuccessResponse> {
try {
Expand All @@ -371,12 +379,20 @@ export class Server extends TypedEmitter<ServerEvents> {
}

public async getOrders(
orderFilter: OrderFilter
orderFilter: OrderFilter,
offset: number,
limit: number,
sortField?: SortField,
sortOrder?: SortOrder
): Promise<OrderResponse<FullOrder>> {
try {
return Promise.resolve(
(await this.httpCall('getOrders', [
{ ...this.toBigIntJson(orderFilter) },
offset,
limit,
sortField,
sortOrder,
])) as OrderResponse<FullOrder>
)
} catch (err) {
Expand Down
26 changes: 15 additions & 11 deletions tools/libraries/test/Server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,22 +178,26 @@ describe('HTTPServer', () => {
.nock('https://' + URL, mockHttpServer)
.it('Server getOrdersERC20()', async () => {
const server = await Server.at(URL)
const result = await server.getOrdersERC20({
signerWallet: ADDRESS_ZERO,
offset: 0,
limit: 100,
})
const result = await server.getOrdersERC20(
{
signerWallet: ADDRESS_ZERO,
},
0,
100
)
expect(isValidFullOrderERC20(result.orders[0].order)).to.be.true
})
fancy
.nock('https://' + URL, mockHttpServer)
.it('Server getOrders()', async () => {
const server = await Server.at(URL)
const result = await server.getOrders({
signerWallet: ADDRESS_ZERO,
offset: 0,
limit: 100,
})
const result = await server.getOrders(
{
signerWallet: ADDRESS_ZERO,
},
0,
100
)
expect(isValidFullOrder(result.orders[0].order)).to.be.true
})
})
Expand Down Expand Up @@ -500,7 +504,7 @@ describe('WebSocketServer', () => {
})
})

describe('Storage', () => {
describe('Indexing', () => {
it('sort field: should match value', () => {
expect(toSortField('SENDER_AMOUNT')).to.equal(SortField.SENDER_AMOUNT)
expect(toSortField('sender_amount')).to.equal(SortField.SENDER_AMOUNT)
Expand Down
6 changes: 3 additions & 3 deletions tools/metadata/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airswap/metadata",
"version": "4.1.12",
"version": "4.1.13",
"description": "AirSwap: Token Metadata for Developers",
"repository": {
"type": "git",
Expand All @@ -20,8 +20,8 @@
"test": "TS_NODE_COMPILER_OPTIONS='{\"strict\":false}' yarn mocha -r ts-node/esm test/*.ts"
},
"dependencies": {
"@airswap/constants": "4.1.6",
"@airswap/types": "4.1.1",
"@airswap/constants": "4.1.7",
"@airswap/types": "4.1.2",
"@airswap/wrapper": "4.1.5",
"@openzeppelin/contracts": "^4.8.3",
"@uniswap/token-lists": "^1.0.0-beta.24",
Expand Down
2 changes: 1 addition & 1 deletion tools/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airswap/types",
"version": "4.1.1",
"version": "4.1.2",
"description": "AirSwap: Types for Developers",
"repository": {
"type": "git",
Expand Down
25 changes: 11 additions & 14 deletions tools/types/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,19 @@ export enum SortOrder {

export type OrderFilter = {
chainId?: number
nonce?: string
excludeNonces?: string[]
senderMaxAmount?: string
senderMinAmount?: string
senderTokens?: string[]
signerWallet?: string
signerToken?: string
signerId?: string
senderWallet?: string
signerMaxAmount?: string
signerMinAmount?: string
signerTokens?: string[]
senderToken?: string
}

export type OrderERC20Filter = {
chainId?: number
signerWallet?: string
sortField?: SortField
sortOrder?: SortOrder
senderIds?: string[]
signerIds?: string[]
limit: number
offset: number
signerToken?: string
senderWallet?: string
senderToken?: string
}

export type IndexedOrder<Type> = {
Expand Down
6 changes: 3 additions & 3 deletions tools/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airswap/utils",
"version": "4.1.9",
"version": "4.1.10",
"description": "AirSwap: Utilities for Developers",
"repository": {
"type": "git",
Expand All @@ -21,8 +21,8 @@
"test:ci": "yarn test"
},
"dependencies": {
"@airswap/constants": "4.1.6",
"@airswap/types": "4.1.1",
"@airswap/constants": "4.1.7",
"@airswap/types": "4.1.2",
"@metamask/eth-sig-util": "^5.0.2",
"bignumber.js": "^9.0.1",
"ethereumjs-util": "^7.1.5",
Expand Down

0 comments on commit 6b76cbf

Please sign in to comment.