Skip to content

Commit

Permalink
PRO-2029 - PrimeSDK Code Refactor (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
vignesha22 authored Jan 8, 2024
1 parent 1934acb commit 10e81f0
Show file tree
Hide file tree
Showing 64 changed files with 452 additions and 1,100 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Changelog
## [1.4.0]
### Breaking Changes
- Changed the data service to initialise as a seperate entity independent of the primeSdk object
- Removed unnecessary state variables and changed the walletAddress variable name to EOAAddress for better understanding
- Optimised the fetching of accountAddress since before it was fetching from on chain for every request to getCounterFactualAddress from the rpc, now it stores the account address locally in the initialised PrimeSDK object
- Fixed network state variable to output the network which it is connected to

## [1.3.14]
### New
- Added ability to override callDataLimit on estimate step by the user

Expand Down
2 changes: 1 addition & 1 deletion examples/02-transfer-funds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function main() {
// initializating sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' })

console.log('address: ', primeSdk.state.walletAddress)
console.log('address: ', primeSdk.state.EOAAddress)

// get address of EtherspotWallet...
const address: string = await primeSdk.getCounterFactualAddress();
Expand Down
2 changes: 1 addition & 1 deletion examples/03-transfer-erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function main() {
// initializating sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' })

console.log('address: ', primeSdk.state.walletAddress)
console.log('address: ', primeSdk.state.EOAAddress)

// get address of EtherspotWallet...
const address: string = await primeSdk.getCounterFactualAddress();
Expand Down
2 changes: 1 addition & 1 deletion examples/04-transfer-nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function main() {
// initializating sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' })

console.log('address: ', primeSdk.state.walletAddress)
console.log('address: ', primeSdk.state.EOAAddress)

// get address of EtherspotWallet...
const address: string = await primeSdk.getCounterFactualAddress();
Expand Down
20 changes: 8 additions & 12 deletions examples/05-get-account-balances.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { PrimeSdk } from '../src';
import { DataUtils, graphqlEndpoints } from '../src';
import * as dotenv from 'dotenv';

dotenv.config();

async function main() {
// initializating sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, {
chainId: Number(process.env.CHAIN_ID),
projectKey: 'public-prime-testnet-key', // project key
});
// initializating Data service...
const dataService = new DataUtils('public-prime-testnet-key', graphqlEndpoints.QA)

const balances = await primeSdk.getAccountBalances({
account: '', // account address
chainId: 1,
});
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet balances:`, balances);
const balances = await dataService.getAccountBalances({
account: '', // address
chainId: 1,
});
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet balances:`, balances);
}

main()
.catch(console.error)
.finally(() => process.exit());

14 changes: 5 additions & 9 deletions examples/06-transaction.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import { PrimeSdk } from '../src';
import { DataUtils, graphqlEndpoints } 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: 'public-prime-testnet-key', // project key
});
const hash = '0xe6667a1185a6fd93cf082b96f78763514759041940e305da80224609bd1c6781';
const transaction = await primeSdk.getTransaction({ hash });
// initializating Data service...
const dataService = new DataUtils('public-prime-testnet-key', graphqlEndpoints.QA)
const hash = '0x7f8633f21d0c0c71d248333a0a2b976495015109a270a6f8a51befe3baf6fb6e';
const transaction = await dataService.getTransaction({ hash, chainId: 80001 });

console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet transaction:`, transaction);
}

main()
.catch(console.error)
.finally(() => process.exit());

11 changes: 4 additions & 7 deletions examples/08-nft-list.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { PrimeSdk } from '../src';
import { DataUtils, graphqlEndpoints } 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: 'public-prime-testnet-key', // project key
});
// initializating Data service...
const dataService = new DataUtils('public-prime-testnet-key', graphqlEndpoints.QA)
const chainId = 137;
const account = ''; // account address
const nfts = await primeSdk.getNftList({ chainId, account });
const nfts = await dataService.getNftList({ chainId, account });

console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet nfts:`, nfts);
}
Expand Down
14 changes: 6 additions & 8 deletions examples/09-exchange.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import { PrimeSdk } from '../src';
import { DataUtils, graphqlEndpoints } from '../src';
import * as dotenv from 'dotenv';
import { BigNumber, constants } from 'ethers';

dotenv.config();

async function main(): Promise<void> {
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, {
chainId: Number(process.env.CHAIN_ID),
projectKey: 'public-prime-testnet-key', // project key
});

const exchangeSupportedAssets = await primeSdk.getExchangeSupportedAssets({ page: 1, limit: 100 });
// initializating Data service...
const dataService = new DataUtils('public-prime-testnet-key', graphqlEndpoints.QA)
const exchangeSupportedAssets = await dataService.getExchangeSupportedAssets({ page: 1, limit: 100, account: '', chainId: Number(process.env.CHAIN_ID) });
console.log('\x1b[33m%s\x1b[0m', `Found exchange supported assets:`, exchangeSupportedAssets.items.length);

const fromTokenAddress = '0xe3818504c1b32bf1557b16c238b2e01fd3149c17';
const toTokenAddress = constants.AddressZero;
const fromAmount = '1000000000000000000';
const fromChainId = 1;

const offers = await primeSdk.getExchangeOffers({
const offers = await dataService.getExchangeOffers({
fromAddress: '',
fromChainId,
fromTokenAddress,
toTokenAddress,
Expand Down
14 changes: 6 additions & 8 deletions examples/10-advance-routes-lifi.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
import { ethers, utils } from 'ethers';
import { PrimeSdk } from '../src';
import { DataUtils, graphqlEndpoints } 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: 'public-prime-testnet-key', // project key
});
// initializating Data service...
const dataService = new DataUtils('public-prime-testnet-key', graphqlEndpoints.QA)

const fromChainId = 56;
const toChainId = 137;

const fromAmount = utils.parseUnits('1', 18);

const quoteRequestPayload = {
fromAddress: '',
fromChainId: fromChainId,
toChainId: toChainId,
fromTokenAddress: ethers.constants.AddressZero,
toTokenAddress: ethers.constants.AddressZero,
fromAmount: fromAmount,
};

const quotes = await primeSdk.getAdvanceRoutesLiFi(quoteRequestPayload);
const quotes = await dataService.getAdvanceRoutesLiFi(quoteRequestPayload);

console.log('\x1b[33m%s\x1b[0m', `Quotes:`, quotes.items);

if (quotes.items.length > 0) {
const quote = quotes.items[0]; // Selected the first route
const transactions = await primeSdk.getStepTransaction({ route: quote });
const transactions = await dataService.getStepTransaction({ route: quote, account: '' });

console.log('\x1b[33m%s\x1b[0m', `transactions:`, transactions);
}
Expand Down
13 changes: 5 additions & 8 deletions examples/11-cross-chain-quotes.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { utils } from 'ethers';
import { PrimeSdk } from '../src';
import { DataUtils, graphqlEndpoints } from '../src';
import * as dotenv from 'dotenv';
import { BridgingQuotes, CrossChainServiceProvider } from '../src/sdk/data';
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: 'public-prime-testnet-key', // project key
});
// initializating Data service...
const dataService = new DataUtils('public-prime-testnet-key', graphqlEndpoints.QA)

const XdaiUSDC = '0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83'; // Xdai - USDC
const MaticUSDC = '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174'; // Matic - USDC
Expand All @@ -27,12 +24,12 @@ async function main(): Promise<void> {
toChainId: toChainId,
fromTokenAddress: fromTokenAddress,
toTokenAddress: toTokenAddress,
fromAddress: '', // account address
fromAddress: '', // from address
fromAmount: fromAmount,
serviceProvider: CrossChainServiceProvider.LiFi, // Optional parameter
};

const quotes: BridgingQuotes = await primeSdk.getCrossChainQuotes(quoteRequestPayload);
const quotes: BridgingQuotes = await dataService.getCrossChainQuotes(quoteRequestPayload);

console.log('\x1b[33m%s\x1b[0m', `Quotes:`, quotes);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/12-add-guardians.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function main() {
{ chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' },
);

console.log('address: ', primeSdk.state.walletAddress);
console.log('address: ', primeSdk.state.EOAAddress);

// get address of EtherspotWallet
const address: string = await primeSdk.getCounterFactualAddress();
Expand Down
2 changes: 1 addition & 1 deletion examples/13-paymaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function main() {
chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key',
})

console.log('address: ', primeSdk.state.walletAddress)
console.log('address: ', primeSdk.state.EOAAddress)

// get address of EtherspotWallet...
const address: string = await primeSdk.getCounterFactualAddress();
Expand Down
2 changes: 1 addition & 1 deletion examples/16-paymaster-arka.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function main() {
chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key',
})

console.log('address: ', primeSdk.state.walletAddress)
console.log('address: ', primeSdk.state.EOAAddress)

const entryPointAddress = '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789';

Expand Down
31 changes: 14 additions & 17 deletions examples/17-token-list.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
import { PrimeSdk } from '../src';
import { DataUtils, graphqlEndpoints } 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: 'public-prime-testnet-key', // project key
});
// initializating Data service...
const dataService = new DataUtils('public-prime-testnet-key', graphqlEndpoints.QA)

const tokenLists = await primeSdk.getTokenLists();
const tokenLists = await dataService.getTokenLists();

console.log('\x1b[33m%s\x1b[0m', `TokenLists:`, tokenLists);
console.log('\x1b[33m%s\x1b[0m', `TokenLists:`, tokenLists);

const { name } = tokenLists[0];
const { name } = tokenLists[0];

let tokenListTokens = await primeSdk.getTokenListTokens();
let tokenListTokens = await dataService.getTokenListTokens();

console.log('\x1b[33m%s\x1b[0m', `Default token list tokens length:`, tokenListTokens.length);
console.log('\x1b[33m%s\x1b[0m', `Default token list tokens length:`, tokenListTokens.length);

tokenListTokens = await primeSdk.getTokenListTokens({
name,
});
tokenListTokens = await dataService.getTokenListTokens({
name,
});

console.log('\x1b[33m%s\x1b[0m', `${name} token list tokens length:`, tokenListTokens.length);
console.log('\x1b[33m%s\x1b[0m', `${name} token list tokens length:`, tokenListTokens.length);
}

main()
.catch(console.error)
.finally(() => process.exit());
.catch(console.error)
.finally(() => process.exit());
35 changes: 16 additions & 19 deletions examples/18-exchange-rates.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
import { PrimeSdk, RateData } from '../src';
import { DataUtils, RateData, graphqlEndpoints } 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: 'public-prime-testnet-key', // project key
});
// initializating Data service...
const dataService = new DataUtils('public-prime-testnet-key', graphqlEndpoints.QA)

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 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 requestPayload = {
tokens: TOKEN_LIST,
chainId: ETH_CHAIN_ID,
};

const rates: RateData = await primeSdk.fetchExchangeRates(requestPayload);
const rates: RateData = await dataService.fetchExchangeRates(requestPayload);

console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet Rates:`, rates);
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet Rates:`, rates);
}

main()
.catch(console.error)
.finally(() => process.exit());
.catch(console.error)
.finally(() => process.exit());
2 changes: 1 addition & 1 deletion examples/19-paymaster-validUntil-validAfter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function main() {
chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key',
})

console.log('address: ', primeSdk.state.walletAddress)
console.log('address: ', primeSdk.state.EOAAddress)

// get address of EtherspotWallet...
const address: string = await primeSdk.getCounterFactualAddress();
Expand Down
2 changes: 1 addition & 1 deletion examples/20-callDataLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function main() {
// initializating sdk...
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' })

console.log('address: ', primeSdk.state.walletAddress)
console.log('address: ', primeSdk.state.EOAAddress)

// get address of EtherspotWallet...
const address: string = await primeSdk.getCounterFactualAddress();
Expand Down
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/prime-sdk",
"version": "1.3.14",
"version": "1.4.0",
"description": "Etherspot Prime (Account Abstraction) SDK",
"keywords": [
"ether",
Expand Down
Loading

0 comments on commit 10e81f0

Please sign in to comment.