-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added getTokenLists, getTokenListTokens and fetchExchangeRates endpoi…
…nts (#45) * Added getTokenLists, getTokenListTokens and fetchExchangeRates endpoints * Changes as per comments * Changes as per comments * Changed console log to console error
- Loading branch information
1 parent
05a1b05
commit 3d2136d
Showing
17 changed files
with
343 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { PrimeSdk } from '../src'; | ||
import * as dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
async function main(): Promise<void> { | ||
// initializating sdk... | ||
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { | ||
chainId: Number(process.env.CHAIN_ID), | ||
projectKey: '', // project key | ||
}); | ||
|
||
const tokenLists = await primeSdk.getTokenLists(); | ||
|
||
console.log('\x1b[33m%s\x1b[0m', `TokenLists:`, tokenLists); | ||
|
||
const { name } = tokenLists[0]; | ||
|
||
let tokenListTokens = await primeSdk.getTokenListTokens(); | ||
|
||
console.log('\x1b[33m%s\x1b[0m', `Default token list tokens length:`, tokenListTokens.length); | ||
|
||
tokenListTokens = await primeSdk.getTokenListTokens({ | ||
name, | ||
}); | ||
|
||
console.log('\x1b[33m%s\x1b[0m', `${name} token list tokens length:`, tokenListTokens.length); | ||
} | ||
|
||
main() | ||
.catch(console.error) | ||
.finally(() => process.exit()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { PrimeSdk, RateData } from '../src'; | ||
import * as dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
async function main(): Promise<void> { | ||
// initializating sdk... | ||
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { | ||
chainId: Number(process.env.CHAIN_ID), | ||
projectKey: '', // project key | ||
}); | ||
|
||
const ETH_AAVE_ADDR = '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9'; | ||
const ETH_MATIC_ADDR = '0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0'; | ||
const ETH_USDC_ADDR = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'; | ||
const TOKEN_LIST = [ETH_AAVE_ADDR, ETH_MATIC_ADDR, ETH_USDC_ADDR]; | ||
const ETH_CHAIN_ID = 1; | ||
|
||
const requestPayload = { | ||
tokens: TOKEN_LIST, | ||
chainId: ETH_CHAIN_ID, | ||
}; | ||
|
||
const rates: RateData = await primeSdk.fetchExchangeRates(requestPayload); | ||
|
||
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet Rates:`, rates); | ||
} | ||
|
||
main() | ||
.catch(console.error) | ||
.finally(() => process.exit()); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Type } from 'class-transformer'; | ||
import { RateInfo } from './rate-info'; | ||
|
||
export class RateData { | ||
errored: boolean; | ||
|
||
error: string; | ||
|
||
@Type(() => RateInfo) | ||
items: Array<RateInfo>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class RateInfo { | ||
address: string; | ||
eth: number; | ||
eur: number; | ||
gbp: number; | ||
usd: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export class TokenListToken { | ||
address: string; | ||
chainId: number; | ||
name: string; | ||
symbol: string; | ||
decimals: number; | ||
logoURI: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Type } from 'class-transformer'; | ||
import { TokenListToken } from './token-list-token'; | ||
|
||
export class TokenList { | ||
name: string; | ||
|
||
endpoint: string; | ||
|
||
isDefault: boolean; | ||
|
||
@Type(() => TokenListToken) | ||
tokens: TokenListToken[]; | ||
|
||
@Type(() => Date) | ||
createdAt: Date; | ||
|
||
@Type(() => Date) | ||
updatedAt: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Type } from 'class-transformer'; | ||
import { TokenList } from './token-list'; | ||
|
||
export class TokenLists { | ||
@Type(() => TokenList) | ||
items: TokenList[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { IsAddress } from './validators'; | ||
import { ArrayNotEmpty, IsInt, IsPositive } from 'class-validator'; | ||
|
||
export class FetchExchangeRatesDto { | ||
@IsAddress({ | ||
each: true, | ||
}) | ||
@ArrayNotEmpty() | ||
tokens: Array<string>; | ||
|
||
@IsInt() | ||
@IsPositive() | ||
chainId: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { IsString, MinLength, MaxLength, IsOptional } from 'class-validator'; | ||
import { TOKEN_LIST_MAX_NAME_LENGTH, TOKEN_LIST_MIN_NAME_LENGTH } from '../data'; | ||
|
||
export class GetTokenListDto { | ||
@IsOptional() | ||
@IsString() | ||
@MinLength(TOKEN_LIST_MIN_NAME_LENGTH) | ||
@MaxLength(TOKEN_LIST_MAX_NAME_LENGTH) | ||
name?: string = null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.