Skip to content

Commit

Permalink
Allow users to register tokens with comlink
Browse files Browse the repository at this point in the history
This reverts commit 45b22fb.
  • Loading branch information
adamfraser committed Sep 3, 2024
1 parent f0decda commit 6fa3f6d
Show file tree
Hide file tree
Showing 11 changed files with 491 additions and 4 deletions.
2 changes: 2 additions & 0 deletions indexer/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions indexer/services/comlink/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ DB_PORT=5436
RATE_LIMIT_ENABLED=false
INDEXER_LEVEL_GEOBLOCKING_ENABLED=false
EXPOSE_SET_COMPLIANCE_ENDPOINT=true
FIREBASE_PROJECT_ID=projectID
FIREBASE_PRIVATE_KEY='-----BEGIN RSA PRIVATE KEY----------END RSA PRIVATE KEY-----'
FIREBASE_CLIENT_EMAIL=[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
BlockTable,
liquidityTierRefresher,
SubaccountTable,
TokenTable,
} from '@dydxprotocol-indexer/postgres';
import { RequestMethod } from '../../../../src/types';
import request from 'supertest';
Expand Down Expand Up @@ -42,6 +43,7 @@ describe('addresses-controller#V4', () => {

afterEach(async () => {
await dbHelpers.clearData();
jest.clearAllMocks();
});

const invalidAddress: string = 'invalidAddress';
Expand Down Expand Up @@ -574,4 +576,108 @@ describe('addresses-controller#V4', () => {
});
});

describe('/:address/registerToken', () => {
it('Post /:address/registerToken with valid params returns 200', async () => {
const token = 'validToken';
const language = 'en';
const response: request.Response = await sendRequest({
type: RequestMethod.POST,
path: `/v4/addresses/${testConstants.defaultAddress}/registerToken`,
body: { token, language },
expectedStatus: 200,
});

expect(response.body).toEqual({});
expect(stats.increment).toHaveBeenCalledWith('comlink.addresses-controller.response_status_code.200', 1, {
path: '/:address/registerToken',
method: 'POST',
});
});

it('Post /:address/registerToken with valid params calls TokenTable registerToken', async () => {
jest.spyOn(TokenTable, 'registerToken');
const token = 'validToken';
const language = 'en';
await sendRequest({
type: RequestMethod.POST,
path: `/v4/addresses/${testConstants.defaultAddress}/registerToken`,
body: { token, language },
expectedStatus: 200,
});
expect(TokenTable.registerToken).toHaveBeenCalledWith(
token, testConstants.defaultAddress, language,
);
expect(stats.increment).toHaveBeenCalledWith('comlink.addresses-controller.response_status_code.200', 1, {
path: '/:address/registerToken',
method: 'POST',
});
});

it('Post /:address/registerToken with invalid address returns 404', async () => {
const token = 'validToken';
const response: request.Response = await sendRequest({
type: RequestMethod.POST,
path: `/v4/addresses/${invalidAddress}/registerToken`,
body: { token },
expectedStatus: 404,
});

expect(response.body).toEqual({
errors: [
{
msg: 'No address found with address: invalidAddress',
},
],
});
expect(stats.increment).toHaveBeenCalledWith('comlink.addresses-controller.response_status_code.404', 1, {
path: '/:address/registerToken',
method: 'POST',
});
});

it.each([
['validToken', '', 'Invalid language code', 'language'],
['validToken', 'qq', 'Invalid language code', 'language'],
])('Post /:address/registerToken with bad language params returns 400', async (token, language, errorMsg, errorParam) => {
const response: request.Response = await sendRequest({
type: RequestMethod.POST,
path: `/v4/addresses/${testConstants.defaultAddress}/registerToken`,
body: { token, language },
expectedStatus: 400,
});

expect(response.body).toEqual({
errors: [
{
location: 'body',
msg: errorMsg,
param: errorParam,
value: language,
},
],
});
});

it.each([
['', 'en', 'Token cannot be empty', 'token'],
])('Post /:address/registerToken with bad token params returns 400', async (token, language, errorMsg, errorParam) => {
const response: request.Response = await sendRequest({
type: RequestMethod.POST,
path: `/v4/addresses/${testConstants.defaultAddress}/registerToken`,
body: { token, language },
expectedStatus: 400,
});

expect(response.body).toEqual({
errors: [
{
location: 'body',
msg: errorMsg,
param: errorParam,
value: token,
},
],
});
});
});
});
1 change: 1 addition & 0 deletions indexer/services/comlink/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@dydxprotocol-indexer/v4-proto-parser": "workspace:^0.0.1",
"@dydxprotocol-indexer/v4-protos": "workspace:^0.0.1",
"@keplr-wallet/cosmos": "^0.12.122",
"@dydxprotocol-indexer/notifications": "workspace:^0.0.1",
"@tsoa/runtime": "^5.0.0",
"big.js": "^6.2.1",
"body-parser": "^1.20.0",
Expand Down
135 changes: 135 additions & 0 deletions indexer/services/comlink/public/api-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,141 @@ fetch(`${baseURL}/addresses/{address}/parentSubaccountNumber/{parentSubaccountNu
This operation does not require authentication
</aside>

## RegisterToken

<a id="opIdRegisterToken"></a>

> Code samples
```python
import requests
headers = {
'Content-Type': 'application/json'
}

# For the deployment by DYDX token holders, use
# baseURL = 'https://indexer.dydx.trade/v4'
baseURL = 'https://dydx-testnet.imperator.co/v4'

r = requests.post(f'{baseURL}/addresses/{address}/registerToken', headers = headers)

print(r.json())

```

```javascript
const inputBody = '{
"language": "string",
"token": "string"
}';
const headers = {
'Content-Type':'application/json'
};

// For the deployment by DYDX token holders, use
// const baseURL = 'https://indexer.dydx.trade/v4';
const baseURL = 'https://dydx-testnet.imperator.co/v4';

fetch(`${baseURL}/addresses/{address}/registerToken`,
{
method: 'POST',
body: inputBody,
headers: headers
})
.then(function(res) {
return res.json();
}).then(function(body) {
console.log(body);
});

```

`POST /addresses/{address}/registerToken`

> Body parameter
```json
{
"language": "string",
"token": "string"
}
```

### Parameters

|Name|In|Type|Required|Description|
|---|---|---|---|---|
|address|path|string|true|none|
|body|body|object|true|none|
|» language|body|string|true|none|
|» token|body|string|true|none|

### Responses

|Status|Meaning|Description|Schema|
|---|---|---|---|
|204|[No Content](https://tools.ietf.org/html/rfc7231#section-6.3.5)|No content|None|

<aside class="success">
This operation does not require authentication
</aside>

## TestNotification

<a id="opIdTestNotification"></a>

> Code samples
```python
import requests

# For the deployment by DYDX token holders, use
# baseURL = 'https://indexer.dydx.trade/v4'
baseURL = 'https://dydx-testnet.imperator.co/v4'

r = requests.post(f'{baseURL}/addresses/{address}/testNotification')

print(r.json())

```

```javascript

// For the deployment by DYDX token holders, use
// const baseURL = 'https://indexer.dydx.trade/v4';
const baseURL = 'https://dydx-testnet.imperator.co/v4';

fetch(`${baseURL}/addresses/{address}/testNotification`,
{
method: 'POST'

})
.then(function(res) {
return res.json();
}).then(function(body) {
console.log(body);
});

```

`POST /addresses/{address}/testNotification`

### Parameters

|Name|In|Type|Required|Description|
|---|---|---|---|---|
|address|path|string|true|none|

### Responses

|Status|Meaning|Description|Schema|
|---|---|---|---|
|204|[No Content](https://tools.ietf.org/html/rfc7231#section-6.3.5)|No content|None|

<aside class="success">
This operation does not require authentication
</aside>

## GetReferralCode

<a id="opIdGetReferralCode"></a>
Expand Down
64 changes: 64 additions & 0 deletions indexer/services/comlink/public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,70 @@
]
}
},
"/addresses/{address}/registerToken": {
"post": {
"operationId": "RegisterToken",
"responses": {
"204": {
"description": "No content"
}
},
"security": [],
"parameters": [
{
"in": "path",
"name": "address",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"properties": {
"language": {
"type": "string"
},
"token": {
"type": "string"
}
},
"required": [
"language",
"token"
],
"type": "object"
}
}
}
}
}
},
"/addresses/{address}/testNotification": {
"post": {
"operationId": "TestNotification",
"responses": {
"204": {
"description": "No content"
}
},
"security": [],
"parameters": [
{
"in": "path",
"name": "address",
"required": true,
"schema": {
"type": "string"
}
}
]
}
},
"/affiliates/referral_code": {
"get": {
"operationId": "GetReferralCode",
Expand Down
Loading

0 comments on commit 6fa3f6d

Please sign in to comment.