From 489c37085fd92f2b6c76b405441885de604f96e2 Mon Sep 17 00:00:00 2001 From: vignesha22 <82584664+vignesha22@users.noreply.github.com> Date: Tue, 1 Aug 2023 14:05:30 +0530 Subject: [PATCH] PRO - 1694 - OnRamper Integration (#17) * added onRamper * updated version --- CHANGELOG.md | 4 +++ package-lock.json | 6 +++++ package.json | 3 ++- src/sdk/common/constants.ts | 2 ++ src/sdk/dto/index.ts | 3 ++- src/sdk/dto/onRamper.dto.ts | 48 ++++++++++++++++++++++++++++++++++++ src/sdk/network/constants.ts | 2 ++ src/sdk/sdk.ts | 33 ++++++++++++++++++++++--- 8 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 src/sdk/dto/onRamper.dto.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 50595fa2..292749c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +## [1.1.2] - 2023-07-31 +### New +- Added onRamper to get the url + ## [1.1.1] - 2023-07-27 ### New - Added skandha_getGasPrice from the bundler if the bundler url is skandha bundler url diff --git a/package-lock.json b/package-lock.json index 76dd3bbe..39a1afa7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "class-validator": "0.14.0", "commander": "^10.0.1", "ethers": "5.7.0", + "openurl": "1.1.1", "prettier": "^2.8.8", "reflect-metadata": "0.1.13" }, @@ -5213,6 +5214,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/openurl": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/openurl/-/openurl-1.1.1.tgz", + "integrity": "sha512-d/gTkTb1i1GKz5k3XE3XFV/PxQ1k45zDqGP2OA7YhgsaLoqm6qRvARAZOFer1fcXritWlGBRCu/UgeS4HAnXAA==" + }, "node_modules/optionator": { "version": "0.8.3", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz", diff --git a/package.json b/package.json index 7d61839a..cad8043b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@etherspot/prime-sdk", - "version": "1.1.1", + "version": "1.1.2", "description": "Etherspot Prime (Account Abstraction) SDK", "keywords": [ "ether", @@ -46,6 +46,7 @@ "class-validator": "0.14.0", "commander": "^10.0.1", "ethers": "5.7.0", + "openurl": "1.1.1", "prettier": "^2.8.8", "reflect-metadata": "0.1.13" }, diff --git a/src/sdk/common/constants.ts b/src/sdk/common/constants.ts index 04c9c8f2..13861c85 100644 --- a/src/sdk/common/constants.ts +++ b/src/sdk/common/constants.ts @@ -9,3 +9,5 @@ export enum HeaderNames { } export const bufferPercent:number = 13; // Buffer in percent + +export const onRampApiKey = 'pk_prod_01H66WYDRFM95JBTJ4VMGY1FAX'; diff --git a/src/sdk/dto/index.ts b/src/sdk/dto/index.ts index ea9a597a..b2b652a5 100644 --- a/src/sdk/dto/index.ts +++ b/src/sdk/dto/index.ts @@ -1,3 +1,4 @@ export * from './sign-message.dto'; export * from './utils'; -export * from './create-session.dto'; \ No newline at end of file +export * from './create-session.dto'; +export * from './onRamper.dto'; \ No newline at end of file diff --git a/src/sdk/dto/onRamper.dto.ts b/src/sdk/dto/onRamper.dto.ts new file mode 100644 index 00000000..c1261cb0 --- /dev/null +++ b/src/sdk/dto/onRamper.dto.ts @@ -0,0 +1,48 @@ +import { IsOptional, IsPositive, IsInt, IsString, IsBoolean } from 'class-validator'; + +export class OnRamperDto { + @IsOptional() + @IsString() + defaultCrypto?: string; + + @IsOptional() + @IsString() + excludeCryptos?: string; + + @IsOptional() + @IsString() + onlyCryptos?: string; + + @IsOptional() + @IsString() + excludeCryptoNetworks?: string; + + @IsOptional() + @IsString() + onlyCryptoNetworks?: string; + + @IsOptional() + @IsPositive() + @IsInt() + defaultAmount?: number; + + @IsOptional() + @IsString() + defaultFiat?: string; + + @IsOptional() + @IsBoolean() + isAmountEditable?: Boolean; + + @IsOptional() + @IsString() + onlyFiats?: string; + + @IsOptional() + @IsString() + excludeFiats?: string; + + @IsOptional() + @IsString() + themeName?: string; +} diff --git a/src/sdk/network/constants.ts b/src/sdk/network/constants.ts index 17fa61c3..9e327f0e 100644 --- a/src/sdk/network/constants.ts +++ b/src/sdk/network/constants.ts @@ -46,6 +46,8 @@ export const NETWORK_NAME_TO_CHAIN_ID: { [NetworkNames.Mantle]: 5000, }; +export const onRamperAllNetworks = ['OPTIMISM', 'POLYGON', 'ARBITRUM', 'FUSE', 'GNOSIS', 'ETHEREUM'] + export const Networks: { [key: string]: NetworkConfig } = { diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts index adb5a810..80618acf 100644 --- a/src/sdk/sdk.ts +++ b/src/sdk/sdk.ts @@ -1,15 +1,16 @@ import { BehaviorSubject } from 'rxjs'; +import * as open from 'openurl'; import { State, StateService } from './state'; import { isWalletProvider, WalletProviderLike } from './wallet'; import { SdkOptions } from './interfaces'; import { Network } from "./network"; -import { BatchUserOpsRequest, Exception, getGasFee, UserOpsRequest } from "./common"; +import { BatchUserOpsRequest, Exception, getGasFee, onRampApiKey, UserOpsRequest } from "./common"; import { BigNumber, ethers, providers } from 'ethers'; -import { getNetworkConfig, Networks } from './network/constants'; +import { getNetworkConfig, Networks, onRamperAllNetworks } from './network/constants'; import { UserOperationStruct } from './contracts/src/aa-4337/core/BaseAccount'; import { EtherspotWalletAPI, HttpRpcClient } from './base'; import { TransactionDetailsForUserOp, TransactionGasInfoForUserOp } from './base/TransactionDetailsForUserOp'; -import { CreateSessionDto, SignMessageDto, validateDto } from './dto'; +import { CreateSessionDto, OnRamperDto, SignMessageDto, validateDto } from './dto'; import { Session } from '.'; import { ERC20__factory } from './contracts'; @@ -219,4 +220,30 @@ export class PrimeSdk { return callGasLimit.add(verificationGasLimit).add(preVerificationGas); } + async getFiatOnRamp(params: OnRamperDto = {}) { + if (!params.onlyCryptoNetworks) params.onlyCryptoNetworks = onRamperAllNetworks.join(','); + else { + const networks = params.onlyCryptoNetworks.split(','); + for (const network in networks) { + if (!onRamperAllNetworks.includes(network)) throw new Error('Included Networks which are not supported. Please Check'); + } + } + + const url = `https://buy.onramper.com/?networkWallets=ETHEREUM:${await this.getCounterFactualAddress()}` + + `&apiKey=${onRampApiKey}` + + `&onlyCryptoNetworks=${params.onlyCryptoNetworks}` + + `${params.defaultCrypto ? `&defaultCrypto=${params.defaultCrypto}` : ``}` + + `${params.excludeCryptos ? `&excludeCryptos=${params.excludeCryptos}` : ``}` + + `${params.onlyCryptos ? `&onlyCryptos=${params.onlyCryptos}` : ``}` + + `${params.excludeCryptoNetworks ? `&excludeCryptoNetworks=${params.excludeCryptoNetworks}` : ``}` + + `${params.defaultAmount ? `&defaultCrypto=${params.defaultAmount}` : ``}` + + `${params.defaultFiat ? `&defaultFiat=${params.defaultFiat}` : ``}` + + `${params.isAmountEditable ? `&isAmountEditable=${params.isAmountEditable}` : ``}` + + `${params.onlyFiats ? `&onlyFiats=${params.onlyFiats}` : ``}` + + `${params.excludeFiats ? `&excludeFiats=${params.excludeFiats}` : ``}` + + `&themeName=${params.themeName ?? 'dark'}`; + open.open(url) + return url; + } + }