Skip to content

Commit

Permalink
PRO - 1694 - OnRamper Integration (#17)
Browse files Browse the repository at this point in the history
* added onRamper

* updated version
  • Loading branch information
vignesha22 authored Aug 1, 2023
1 parent 04cfede commit 489c370
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@etherspot/prime-sdk",
"version": "1.1.1",
"version": "1.1.2",
"description": "Etherspot Prime (Account Abstraction) SDK",
"keywords": [
"ether",
Expand Down Expand Up @@ -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"
},
Expand Down
2 changes: 2 additions & 0 deletions src/sdk/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ export enum HeaderNames {
}

export const bufferPercent:number = 13; // Buffer in percent

export const onRampApiKey = 'pk_prod_01H66WYDRFM95JBTJ4VMGY1FAX';
3 changes: 2 additions & 1 deletion src/sdk/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './sign-message.dto';
export * from './utils';
export * from './create-session.dto';
export * from './create-session.dto';
export * from './onRamper.dto';
48 changes: 48 additions & 0 deletions src/sdk/dto/onRamper.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 2 additions & 0 deletions src/sdk/network/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
} = {
Expand Down
33 changes: 30 additions & 3 deletions src/sdk/sdk.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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;
}

}

0 comments on commit 489c370

Please sign in to comment.