Skip to content

Commit

Permalink
PRO-1672: Added Data Wrapper (#18)
Browse files Browse the repository at this point in the history
* Added data wapper and new endpoints
* Added project-key validation on data-wrapper endpoints and fixed linting check
* updated package version
* fixed linting errors
  • Loading branch information
kaushalrajbacancy authored Aug 24, 2023
1 parent cc224d9 commit b32597d
Show file tree
Hide file tree
Showing 87 changed files with 4,120 additions and 226 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist
coverage
__snapshots__
__snapshots__
src/sdk/contracts/**/*.ts
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ module.exports = {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/camelcase': 'off',
},
};
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
# Changelog

## [1.1.7] - 2023-08-24
### New
- Added getAccountBalances to get account balances
- Added getTransaction to get transaction
- Added getTransactions to get transactions
- Added getNftList to get NFT list belonging to account
- Added getExchangeOffers to get exchange offers
- Added getAdvanceRoutesLiFi to get advance routes
- Added getStepTransaction to get step transaction from LIFI
- Added getCrossChainQuotes to get multi chain quotes
## [1.1.6] - 2023-08-24
### Bug Fixes
- Fixes on User hash was created before initialising the paymaster response if given which leads to "Invalid signature or paymaster signature"
Expand Down
4 changes: 2 additions & 2 deletions examples/02-transfer-funds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { sleep } from '../src/sdk/common';

dotenv.config();

const recipient: string = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address
const value: string = '0.01'; // transfer value
const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address
const value = '0.01'; // transfer value

async function main() {
// initializating sdk...
Expand Down
8 changes: 4 additions & 4 deletions examples/03-transfer-erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { sleep } from '../src/sdk/common';
dotenv.config();

// add/change these values
const recipient: string = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address
const value: string = '0.1'; // transfer value
const tokenAddress: string = '0x326C977E6efc84E512bB9C30f76E30c160eD06FB';
const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address
const value = '0.1'; // transfer value
const tokenAddress = '0x326C977E6efc84E512bB9C30f76E30c160eD06FB';

async function main() {
// initializating sdk...
Expand All @@ -36,7 +36,7 @@ async function main() {
await primeSdk.clearUserOpsFromBatch();

// add transactions to the batch
let userOpsBatch = await primeSdk.addUserOpsToBatch({to: tokenAddress, data: transactionData});
const userOpsBatch = await primeSdk.addUserOpsToBatch({to: tokenAddress, data: transactionData});
console.log('transactions: ', userOpsBatch);

// estimate transactions added to the batch and get the fee data for the UserOp
Expand Down
6 changes: 3 additions & 3 deletions examples/04-transfer-nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { sleep } from '../src/sdk/common';
dotenv.config();

// add/change these values
const recipient: string = '0xD129dB5e418e389c3F7D3ae0B8771B3f76799A52'; // recipient wallet address
const tokenAddress: string = '0xe55C5793a52AF819fBf3e87a23B36708E6FDd2Cc';
const recipient = '0xD129dB5e418e389c3F7D3ae0B8771B3f76799A52'; // recipient wallet address
const tokenAddress = '0xe55C5793a52AF819fBf3e87a23B36708E6FDd2Cc';
const tokenId = 4;

async function main() {
Expand All @@ -31,7 +31,7 @@ async function main() {
await primeSdk.clearUserOpsFromBatch();

// add transactions to the batch
let userOpsBatch = await primeSdk.addUserOpsToBatch({to: tokenAddress, data: erc721Data});
const userOpsBatch = await primeSdk.addUserOpsToBatch({to: tokenAddress, data: erc721Data});
console.log('transactions: ', userOpsBatch);

// sign transactions added to the batch
Expand Down
23 changes: 23 additions & 0 deletions examples/05-get-account-balances.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { PrimeSdk } 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: '', // project key
});

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

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

21 changes: 21 additions & 0 deletions examples/06-transaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 hash = '0xe6667a1185a6fd93cf082b96f78763514759041940e305da80224609bd1c6781';
const transaction = await primeSdk.getTransaction({ hash });

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

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

22 changes: 22 additions & 0 deletions examples/07-transactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 chainId = 1;
const account = ''; // account address
const transactions = await primeSdk.getTransactions({ chainId, account });

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

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

21 changes: 21 additions & 0 deletions examples/08-nft-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 chainId = 137;
const account = ''; // account address
const nfts = await primeSdk.getNftList({ chainId, account });

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

main()
.catch(console.error)
.finally(() => process.exit());
29 changes: 29 additions & 0 deletions examples/09-exchange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { PrimeSdk } 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: '', // project key
});
const fromTokenAddress = '0xe3818504c1b32bf1557b16c238b2e01fd3149c17';
const toTokenAddress = constants.AddressZero;
const fromAmount = '1000000000000000000';
const fromChainId = 1;

const offers = await primeSdk.getExchangeOffers({
fromChainId,
fromTokenAddress,
toTokenAddress,
fromAmount: BigNumber.from(fromAmount),
});

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

main()
.catch(console.error)
.finally(() => process.exit());
40 changes: 40 additions & 0 deletions examples/10-advance-routes-lifi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ethers, utils } from 'ethers';
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 fromChainId = 56;
const toChainId = 137;

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

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

const quotes = await primeSdk.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 });

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

main()
.catch(console.error)
.finally(() => process.exit());
42 changes: 42 additions & 0 deletions examples/11-cross-chain-quotes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { utils } from 'ethers';
import { PrimeSdk } 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: '', // project key
});

const XdaiUSDC = '0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83'; // Xdai - USDC
const MaticUSDC = '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174'; // Matic - USDC

const fromChainId = 137;
const toChainId = 100;
const fromTokenAddress: string = MaticUSDC;
const toTokenAddress: string = XdaiUSDC;

// MATIC USDC has 6 decimals
const fromAmount = utils.parseUnits('1', 6); // 10 USDC

const quoteRequestPayload = {
fromChainId: fromChainId,
toChainId: toChainId,
fromTokenAddress: fromTokenAddress,
toTokenAddress: toTokenAddress,
fromAddress: '', // account address
fromAmount: fromAmount,
serviceProvider: CrossChainServiceProvider.LiFi, // Optional parameter
};

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

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

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

0 comments on commit b32597d

Please sign in to comment.