Skip to content

Commit

Permalink
Added Net curve API (#222)
Browse files Browse the repository at this point in the history
* Added netcurve api

* Revemod private key of random wallet

* Removed wallet address

* Update package version

* Change pipeline image

* Updated netcurve apichanges implementation

---------

Co-authored-by: vnovacev <novacev@yahoo.com>
  • Loading branch information
kaushalrajbacancy and vnovacev committed May 2, 2023
1 parent 53c49eb commit 960085c
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
install:
working_directory: ~/etherspot-sdk
docker:
- image: circleci/node:14.17.0
- image: cimg/node:14.21.3
auth:
username: $DOCKERHUB_USER
password: $DOCKERHUB_PASSWORD
Expand All @@ -33,7 +33,7 @@ jobs:
publish:
working_directory: ~/etherspot-sdk
docker:
- image: circleci/node:14.17.0
- image: cimg/node:14.21.3
auth:
username: $DOCKERHUB_USER
password: $DOCKERHUB_PASSWORD
Expand Down
3 changes: 2 additions & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"27-pools-activity" : "../node_modules/.bin/ts-node ./src/27-pools-activity.ts",
"28-number-of-transactions" : "../node_modules/.bin/ts-node ./src/28-number-of-transactions.ts",
"29-trading-history" : "../node_modules/.bin/ts-node ./src/29-trading-history.ts",
"30-market-details" : "../node_modules/.bin/ts-node ./src/30-market-details.ts"
"30-market-details" : "../node_modules/.bin/ts-node ./src/30-market-details.ts",
"31-net-curve-balances" : "../node_modules/.bin/ts-node ./src/31-net-curve-balances.ts"
},
"dependencies": {
"dotenv": "16.0.1"
Expand Down
44 changes: 44 additions & 0 deletions examples/src/31-net-curve-balances.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Wallet } from 'ethers';
import { EnvNames, NetworkNames, Sdk } from '../../src';
import { logger } from './common';

async function main(): Promise<void> {
const wallet = Wallet.createRandom();

logger.log('sender wallet', wallet.address);

const sdk = new Sdk(wallet, {
projectKey: 'testProject',
projectMetadata: 'test',
env: EnvNames.LocalNets,
networkName: NetworkNames.LocalA,
});

const { state } = sdk;

logger.log('key account', state.account);

logger.log(
'contract account',
await sdk.computeContractAccount({
sync: false,
}),
);

await sdk.syncAccount();

logger.log('synced contract account', state.account);
logger.log('synced contract account member', state.accountMember);

logger.log(
'get market details of token',
await sdk.getAccount24HourNetCurve({
chainIds: [1], // Linked chain ids (optional)
account: '',
}),
);
}

main()
.catch(logger.error)
.finally(() => process.exit());
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "etherspot",
"version": "1.43.1",
"version": "1.43.2",
"description": "Etherspot SDK",
"keywords": [
"ether",
Expand Down
10 changes: 10 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ type AccountInvestments {
items: [AccountInvestment!]!
}

type NetCurveBalance {
timestamp: number
usdValue: number
}

type NetCurveBalances {
items: [NetCurveBalance!]!
}

type AccountDashboardChange {
balance: Float!
netChange: Float!
Expand Down Expand Up @@ -669,6 +678,7 @@ type Query {
account(account: String!, chainId: Int): Account
accountBalances(account: String!, chainId: Int, tokens: [String!] = [], provider: String!): AccountBalances!
accountInvestments(account: String!, chainId: Int, apps: [String!] = [], provider: String!) : AccountInvestments!
netCurveBalances(account: String!, chainIds: [Int!]) : NetCurveBalances!
accountMember(account: String!, chainId: Int, member: String!): AccountMember
accountMembers(account: String!, chainId: Int, limit: Int = 10, page: Int = 1): AccountMembers!
accountSettings(account: String!, chainId: Int): AccountSettings
Expand Down
31 changes: 31 additions & 0 deletions src/sdk/account/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Accounts,
AccountSettings,
AccountTotalBalances,
NetCurveBalances,
} from './classes';
import { AccountMemberStates, AccountMemberTypes, AccountTypes, Currencies } from './constants';
import { IsEligibleForAirdropDto, UpdateAccountSettingsDto } from '../dto';
Expand Down Expand Up @@ -308,6 +309,36 @@ export class AccountService extends Service {

return result;
}

async getAccount24HourNetCurve(account: string, chainIds?: number[]): Promise<NetCurveBalances> {
const { apiService } = this.services;

const { result } = await apiService.query<{
result: NetCurveBalances;
}>(
gql`
query($chainIds: [Int!], $account: String!) {
result: netCurveBalances(chainIds: $chainIds, account: $account) {
items {
usdValue
timestamp
}
}
}
`,
{
variables: {
account,
chainIds,
},
models: {
result: NetCurveBalances,
},
},
);

return result;
}

async getAccountDashboard(account: string, currency: string, days?: number): Promise<AccountDashboard> {
const { apiService } = this.services;
Expand Down
2 changes: 2 additions & 0 deletions src/sdk/account/classes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export * from './accounts';
export * from './account-investment';
export * from './account-investments';
export * from './account-investment-positions-info';
export * from './net-curve-balance';
export * from './net-curve-balances';
5 changes: 5 additions & 0 deletions src/sdk/account/classes/net-curve-balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class NetCurveBalance {
timestamp: number;

usdValue: number;
}
7 changes: 7 additions & 0 deletions src/sdk/account/classes/net-curve-balances.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Type } from 'class-transformer';
import { NetCurveBalance } from './net-curve-balance';

export class NetCurveBalances {
@Type(() => NetCurveBalance)
items: NetCurveBalance[];
}
11 changes: 11 additions & 0 deletions src/sdk/dto/get-account-24hour-net-curve.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IsOptional } from 'class-validator';
import { IsAddress } from './validators';

export class GetAccount24HourNetCurveDto {
@IsOptional()
@IsAddress()
account?: string = null;

@IsOptional()
chainIds?: number[];
}
1 change: 1 addition & 0 deletions src/sdk/dto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,4 @@ export * from './get-token-details.dto';
export * from './get-historical-token-price.dto';
export * from './get-pools-activity.dto';
export * from './get-trading-history.dto';
export * from './get-account-24hour-net-curve.dto';
22 changes: 22 additions & 0 deletions src/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
AccountSettings,
AccountTotalBalances,
AccountTypes,
NetCurveBalances,
} from './account';
import { ApiService } from './api';
import { AssetsService, HistoricalTokenPrices, MarketDetails, NativeCurrenciesItem, NumberOfTransactions, PaginatedTokens, PoolsActivities, TokenDetails, TokenList, TokenListToken, TradingHistories } from './assets';
Expand Down Expand Up @@ -116,6 +117,7 @@ import {
GetHistoricalTokenPriceDto,
GetPoolsActivityDto,
GetTradingHistoryDto,
GetAccount24HourNetCurveDto,
} from './dto';
import { ENSNode, ENSNodeStates, ENSRootNode, ENSService, parseENSName } from './ens';
import { Env, EnvNames } from './env';
Expand Down Expand Up @@ -824,6 +826,26 @@ export class Sdk {
);
}

/**
* gets account 24 hour net curve data
* @param dto
* @return Promise<NetCurveBalances>
*/
async getAccount24HourNetCurve(dto: GetAccount24HourNetCurveDto = {}): Promise<NetCurveBalances> {
const { account, chainIds } = await validateDto(dto, GetAccount24HourNetCurveDto, {
addressKeys: ['account'],
});

await this.require({
wallet: !account,
});

return this.services.accountService.getAccount24HourNetCurve(
this.prepareAccountAddress(account), //
chainIds,
);
}

/**
* gets account total balances
* @param dto
Expand Down

0 comments on commit 960085c

Please sign in to comment.