Skip to content

Commit

Permalink
added onRamper
Browse files Browse the repository at this point in the history
  • Loading branch information
vignesha22 committed Jul 31, 2023
1 parent 04cfede commit cf5ce54
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 4 deletions.
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.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
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 cf5ce54

Please sign in to comment.