Skip to content

Commit

Permalink
Alchemy, zerodev support added (#65)
Browse files Browse the repository at this point in the history
* tests and safe deploy fun

* internal functions mocking

* tests updated

* Signer fix and biconomy get wallets function (#20)

* signer constructor requirement removed

* biconomy get all wallets function added

* types added for multiple params

* testing workflow added

* Sdk bug fixes (#21)

* nft tokenId added

* types file name change

* readme update

* nft transfer gasless updated

* package version changes

* Update README.md

* Update README.md - CRITICAL (#26)

Updated the rebranded form link

* Update README.md (#24)

* Update README.md

Fixed typo

* relayer key added

---------

Co-authored-by: Anshul Yadav <55681256+anshulforyou@users.noreply.github.com>

* estimation implementation for both non gasless and gasless flow (#25)

* gas estimation addition

* fixes

* fixes and tests update

* sig transfer file removed

* insufficient balance unit test added

---------

Co-authored-by: Anshul Yadav <55681256+anshulforyou@users.noreply.github.com>

* Nft edge cases fix (#29)

* duplicate entry bug fix

* amount edge case fix

* optimised and refactored the code

* nft tests updated for gas estimation

* types check added (#30)

* Feat/linting enabled (#31)

* types check added

* linting enabled fix

* pre hook commit

* Cosmetic/code refactoring (#33)

* code division

* native token refactor

* Permit2 transactions refactor

* test fix for not a function issue and some lint rule

* test failed fix added

* minor fixes

---------

Co-authored-by: talhamalik883 <talhamalik883@gmail.com>

* readme bugfix

* test script for both gasless and non gasless and bug fixes (#32)

* test script for both gasless and non gasless and bug fixes

* test fixes

* only balances flag addition

* added scripts as pre-commit hook

* merge changes

* fixes and scripts update

* url fix

---------

Co-authored-by: Anshul Yadav <55681256+anshulforyou@users.noreply.github.com>

* Update README.md (#37)

Updated the booking link with the new team Calendly link.

* Fix/gasless bug (#36)

* gasless bug

* test update

* transaction messages

* formatting

* bug fix

* test fixes

* single permit2 unit test added

* lint changes

* POLYGON fix for USDC permit

* permitToken wait bug fix

* error fix

---------

Co-authored-by: Anshul Yadav <55681256+anshulforyou@users.noreply.github.com>

* arbitrum goerli support added (#38)

* arbitrum goerli support added

* arbitrum goerli scripts added and tested

* version update

* minor changes

* Feat/wallet deployment (#41)

* walelt deployment and native transfer

* formatting

* safe bug fix

* bug fixes

* permit bug fix (#42)

* permit bug fix

* transfer available tokens

---------

Co-authored-by: talhamalik883 <talhamalik883@gmail.com>

* package version update

* readme updated (#45)

* readme updated

* wallet deploy bug fixes

* formatting changes

---------

Co-authored-by: Anshul Yadav <55681256+anshulforyou@users.noreply.github.com>

* minor fixes

* Feat/gasless gelato (#46)

* readme updated

* gasless endpoint integration

* tokenInfo changed to array

* url updated

* test fixes

* gasless updates in sdk

* forward implementation (#48)

* foward implementation

* fixes

* fixes added

* test fix and gasPrice endpoint consumption

* Feat/forward (#51)

* readme updated

* gasless endpoint integration

* tokenInfo changed to array

* url updated

* test fixes

* gasless updates in sdk

* foward implementation

* fixes

* fixes added

* test fix and gasPrice endpoint consumption

* final fixes

* url update

* sepolia support

* msg fix

* package release changes

* minor change

* publish cmd added

* Fix/ux error messages (#54)

* bug fix for ux

* fixes

* gelato package removed (#57)

* BigNumber fixes (#59)

* BigNumber fixes

* BigNumber fixes

* package version update

* Feat/alchemy zerodev support (#62)

* alchemy support added

* zerodev support added

* zerodev wallet bug fixes

* alchemy tests added

* zerodev unit tests added

* Unwanted abis removed

* generalised the wallet addresses

* add: dashboard image updated (#64)

* wallet index added

---------

Co-authored-by: talhamalik883 <talhamalik883@gmail.com>
Co-authored-by: Ari <52634803+theblackmace@users.noreply.github.com>
Co-authored-by: megabyte <yashygkf@gmail.com>
  • Loading branch information
4 people committed Jan 17, 2024
1 parent f2386c7 commit 605f09f
Show file tree
Hide file tree
Showing 21 changed files with 1,166 additions and 1,679 deletions.
1 change: 0 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
npm run lint
npm run format
npm run test
npm run build
npm run execute:nongasless
npm run execute:gasless
npm run execute:forward
Expand Down
178 changes: 98 additions & 80 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The Aarc SDK is a TypeScript library that makes it easy for developers to transf
- ERC20Permit support for streamlined token approvals.
- Gasless transactions using Relayers (EIP2771).

# Getting Started

## Prerequisites
- Node.js (v12.x or later)
- Basic understanding of Ethereum and smart contracts.
Expand All @@ -18,11 +20,15 @@ Install ethers.js and Aarc SDK using npm:
npm install ethers@5.7.2 aarc-sdk
```

# Getting Started

## Get the API Key

To use Aarc SDK, an API key is required. Fill out [this form](https://rebrand.ly/aarc-api) to get the API Key on your email instantly!
To use Aarc SDK, an API key is required. Get the **API Key** from the [Dashboard](https://dashboard.aarc.xyz/).
You can learn about getting the API Key from [here](https://docs.aarc.xyz/developer-docs/integration-guide/setup-and-installation).

![Dashboard Image](./readme_assets/1.png)

> [!NOTE]
We only accept funds on **Polygon Mainnet** & **Polygon Mumbai Testnet**. However, these funds can be transacted on any supported mainnet or testnet.

## Initialise the SDK

Expand All @@ -39,8 +45,16 @@ let aarcSDK = new AarcSDK({
```

# Usage

## Fetching token balances
- [Fetching Token Balances](#fetching-token-balances)
- [Migrate Assets](#migrate-assets)
- [Migrate Assets \[With Gasless Flow\]](#migrate-assets-with-gasless-flow)
- [Migrate Assets \[Pay Gas with Stables\]](#migrate-assets-pay-gas-with-stables)
- [Smart Wallet Integration](#smart-wallet-integration)
- [Smart Wallet Deployment](#smart-wallet-deployment)
- [Get Smart Wallet Addresss](#get-smart-wallet-address)
- [Migrate Native Tokens and Wallet Deployment](#migrate-native-tokens-and-wallet-deployment)

## Fetching Token Balances

Retrieve balances of all tokens in an EOA wallet:

Expand All @@ -52,7 +66,8 @@ let balances = await aarcSDK.fetchBalances(
);
```

## Moving Assets

## Migrate Assets

Transfer tokens from EOA to any receiver wallet address:

Expand All @@ -64,7 +79,7 @@ await aarcSDK.executeMigration({
[
{
tokenAddress:TOKEN1_ADDRESS,
amount?:TOKEN1_AMOUNT, // ethers.BigNumber in case of erc20 and native token
amount?:TOKEN1_AMOUNT.toString(16), // Vaule in HEX as String
tokenIds?: string[] // tokenIds for nfts
},
...
Expand All @@ -73,23 +88,23 @@ await aarcSDK.executeMigration({
// Returns the response given below
```

Output:
### Output:
```bash
[
{
tokenAddress,
amount,
message,
txHash,
tokenId
tokenAddress: string;
taskId?: string;
amount?: string;
message: string;
txHash?: string;
tokenId?: string;
},
...
]
```

### Moving Assets without gas
## Migrate Assets [With Gasless Flow]

Transfer tokens from EOA to any receiver wallet address without gas fees. Please note that we use Gelato Relayer to provide the gasless functionality. Please get the Gelato [API Key](https://docs.gelato.network/developer-services/relay/payment-and-fees/1balance-and-relay) to use the gasless functionality.
Transfer tokens from EOA to any receiver wallet address **without paying gas fees**.

```typescript
await aarcSDK.executeMigrationGasless({
Expand All @@ -99,121 +114,124 @@ await aarcSDK.executeMigrationGasless({
[
{
tokenAddress:TOKEN1_ADDRESS,
amount?:TOKEN1_AMOUNT, // ethers.BigNumber in case of erc20 and native token
amount?:TOKEN1_AMOUNT.toString(16), // Vaule in HEX as String
tokenIds?: string[] // tokenIds for nfts
},
...
],
gelatoApiKey: GELATO_RELAYER_API_KEY // Use the link above to get the gelato relayer key
]
})
// Returns the response given below
```

Output:
### Output:
```bash
[
{
tokenAddress,
amount,
message,
txHash,
tokenId
tokenAddress: string;
taskId?: string;
amount?: string;
message: string;
txHash?: string;
tokenId?: string;
},
...
]
```

## Moving Native Tokens and Wallet Deployment

The following code snippet demonstrates a method to transfer native tokens while simultaneously deploying a wallet using the aarcSDK.

This code snippet illustrates a process to transfer native tokens and deploy a wallet concurrently using the aarcSDK. Essential parameters such as the owner's address (EOA_ADDRESS), the type of wallet to deploy (WALLET_TYPE), the signer (ethers.signer object), the receiver's wallet address (RECEIVER_WALLET_ADDRESS), an optional amount of tokens to transfer (amount), and an index for deploying multiple wallets under the same EOA (deploymentWalletIndex) are included.
## Migrate Assets [Pay Gas with Stables]

#### NOTE
If the wallet corresponding to the provided owner address (EOA_ADDRESS) and index (deploymentWalletIndex) is already deployed, the deployment process will not occur, and only the token transfer will be executed.
Transfer tokens from EOA to any receiver wallet address by **paying gas in Stable Coins.**

```typescript
await aarcSDK.executeForwardTransaction({
senderSigner: signer,
receiverAddress:"0x786E6045eacb96cAe0259cd761e151b68B85bdA7"
});
```

> [!NOTE]
AARC SDK currently supports a few of the Stable Tokens on different networks. You can check about them [here](https://docs.aarc.xyz/developer-docs/integration-guide/usage/assets-migration/user-pays-gas-with-erc20-tokens-forwarder-flow#supported-networks-and-tokens).

```typescript
import { WALLET_TYPE } from "aarc-sdk/dist/utils/AarcTypes";

await aarcSDK.transferNativeAndDeploy({
owner: EOA_ADDRESS,
walletType: WALLET_TYPE, // WALLET_TYPE.SAFE or WALLET_TYPE.BICONOMY
signer: signer, // ethers.signer object
receiverAddress: RECEIVER_WALLET_ADDRESS,
amount: BigNumber, // Optional. if not paseed 80% of native tokens will get transferred.
deploymentWalletIndex: 0 // Optional -- Number: Since an EOA, can be used to deploy multiple wallets. you can supply any index and it will deploy wallet for you
})
// Returns the response given below
```

## Smart Wallet Integration
The Aarc SDK seamlessly integrates with different smart wallets. It currently supports Safe and Biconomy smart wallets and will add more options in the future.
The Aarc SDK seamlessly integrates with different smart wallets.

### Safe smart wallet
Aarc SDk currently supports the following Smart Wallet Providers:
- Safe
- Biconomy
- Alchemy
- ZeroDev

Fetching Existing Safes:

Retrieve a list of all Safe smart wallets associated with the user's EOA:
```typescript
const safes = await aarcSDK.getAllSafes(owner: string); // owner's eoaAddress
// This returns an array of Safe wallet addresses
enum WALLET_TYPE {
BICONOMY,
SAFE,
ALCHEMY,
ZERODEV,
}
```

Creating a New Safe Wallet:
### Smart Wallet Deployment

Generate a new Safe smart wallet. The address returned is a counterfactual address, and the wallet needs to be deployed later. Asset migration can be directed to this address even before deployment.
```typescript
const newSafeAddress = await aarcSDK.generateSafeSCW(
config: {owners: string[], threshold: number},
saltNonce?: number // default value is 0
);
// Returns a counterfactual address for the new Safe wallet
```
You have the capability to deploy Smart Wallets by utilizing the provided code snippets.

The code snippet below showcases how to deploy a wallet using the AarcSDK. It involves specifying essential parameters such as the owner's address (`EOA_ADDRESS`), the type of wallet (`WALLET_TYPE`) to deploy, the `signer` (ethers.signer object), and an optional index for deploying multiple wallets under the same EOA.

### Biconomy Smart Wallet
> [!NOTE]
If the wallet corresponding to the provided owner address (`EOA_ADDRESS`) and index (`deploymentWalletIndex`) is already deployed, the deployment process will not occur.

Fetching Biconomy Smart Wallets:

Retrieve a list of all Biconomy smart wallets associated with the user's EOA:
```typescript
const biconomySWs = await aarcSDK.getAllBiconomySCWs(owner: string); // owner's eoaAddress
// This returns an array of Biconomy wallet addresses
import { WALLET_TYPE } from "aarc-sdk/dist/utils/AarcTypes";

await aarcSDK.deployWallet({
owner: EOA_ADDRESS,
walletType: WALLET_TYPE.SAFE, // Smart Contract Wallet Provider.SAFE, // Smart Contract Wallet Provider
signer: signer, // ethers.signer object
deploymentWalletIndex: 0 // Optional -- Number: Since an EOA, can be used to deploy multiple wallets. you can supply any index and it will deploy wallet for you
})
```

Creating a New Biconomy Wallet:
### Get Smart Wallet Address

To get the address of your Smart Wallet you can use the following code snippet:

The code snippet below showcases how to get a **smart wallet address** using the AarcSDK. It involves specifying essential parameters such as the owner's address (`EOA_ADDRESS`) and the type of wallet (`WALLET_TYPE`).

Similar to the Safe wallet, you can create a Biconomy smart wallet. The address provided is also a counterfactual address, requiring later deployment. The migration process can target this address immediately.
```typescript
const newBiconomySCWAddress = await aarcSDK.generateBiconomySCW(
signer // wallet owner's ethers.signer object
);
// Returns a counterfactual address for the new Biconomy wallet
import { WALLET_TYPE } from "aarc-sdk/dist/utils/AarcTypes";

await aarcSDK.getSmartWalletAddresses({
walletType: WALLET_TYPE.SAFE, // Smart Contract Wallet Provider
owner: OWNER_ADDRESS // Smart Wallet Owner's address
});
```

## Wallet Deployment
### Migrate Native Tokens and Wallet Deployment

You have the capability to deploy Biconomy or Safe wallets by utilizing the provided code snippets.
The following code snippet demonstrates a method to transfer native tokens while simultaneously deploying a wallet using the aarcSDK.

The code snippet below showcases how to deploy a wallet using the AarcSDK. It involves specifying essential parameters such as the owner's address (EOA_ADDRESS), the type of wallet to deploy (WALLET_TYPE.BICONOMY or WALLET_TYPE.SAFE), the signer (ethers.signer object), and an optional index for deploying multiple wallets under the same EOA.
This code snippet illustrates a process to transfer native tokens and deploy a wallet concurrently using the `aarcSDK`. Essential parameters such as the owner's address (`EOA_ADDRESS`), the type of wallet to deploy (`WALLET_TYPE`), the `signer` (ethers.signer object), the receiver's wallet address (`RECEIVER_WALLET_ADDRESS`), an optional amount of tokens to transfer (`amount`), and an index for deploying multiple wallets under the same EOA (`deploymentWalletIndex`) are included.

#### NOTE
If the wallet corresponding to the provided owner address (EOA_ADDRESS) and index (deploymentWalletIndex) is already deployed, the deployment process will not occur.
> [!NOTE]
If the wallet corresponding to the provided owner address (`EOA_ADDRESS`) and index (`deploymentWalletIndex`) is already deployed, the deployment process will not occur, and only the token transfer will be executed.


```typescript
import { WALLET_TYPE } from "aarc-sdk/dist/utils/AarcTypes";

await aarcSDK.deployWallet({
await aarcSDK.transferNativeAndDeploy({
owner: EOA_ADDRESS,
walletType: WALLET_TYPE, // WALLET_TYPE.SAFE or WALLET_TYPE.BICONOMY
walletType: WALLET_TYPE, // Smart Contract Wallet Provider
signer: signer, // ethers.signer object
receiverAddress: RECEIVER_WALLET_ADDRESS,
amount?: TOKEN_AMOUNT.toString(16), // Optional. Vaule in HEX as String. If not paseed 80% of native tokens will get transferred.
deploymentWalletIndex: 0 // Optional -- Number: Since an EOA, can be used to deploy multiple wallets. you can supply any index and it will deploy wallet for you
})
// Returns the response given below
```

#### More coming soon
### More coming soon 👀

## License
This project is licensed under the MIT License - see the [LICENSE](./LICENSE.md) for details.
Expand Down
Loading

0 comments on commit 605f09f

Please sign in to comment.