Skip to content

Commit

Permalink
Aarc SDK 0.0.1-beta.6 (#39)
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

---------

Co-authored-by: talhamalik883 <talhamalik883@gmail.com>
Co-authored-by: Ari <52634803+theblackmace@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 1, 2023
1 parent 0c3f88a commit fa48b0a
Show file tree
Hide file tree
Showing 18 changed files with 904 additions and 100 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,4 @@ const newBiconomySCWAddress = await aarcSDK.generateBiconomySCW(
This project is licensed under the MIT License - see the [LICENSE](./LICENSE.md) for details.

## Support and Feedback
For support or to share feedback, please schedule a 15 min catchup [here](https://calendly.com/arihant-aarc/15min). You can also share your ideas and feedback on the [community forum](https://aarc.featurebase.app/).
For support or to share feedback, please schedule a call with us [here](https://calendly.com/d/3f7-9gt-4pr/session-with-aarc-team). You can also share your ideas and feedback on our [community forum](https://aarc.featurebase.app/).
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": "aarc-sdk",
"version": "0.0.1-beta.5",
"version": "0.0.1-beta.6",
"description": "The Aarc SDK is a TypeScript library that makes it easy for developers to transfer assets from Externally Owned Accounts (EOA) to any destination address. It simplifies the asset transfer process by supporting various token standards, such as ERC20 and ERC721, and offering custom flows like batched transactions, gasless transactions, and paying gas fees with the same asset being moved. Additionally, it enables custom contract interaction within the same transaction using permit2(), allowing for direct swaps and bridge functionality.",
"main": "dist/index.js",
"scripts": {
Expand Down
17 changes: 13 additions & 4 deletions scripts/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export const GELATO_API_KEY = process.env.GELATO_API_KEY || "";

export enum ChainID {
GOERLI = 5,
MUMBAI = 80001
MUMBAI = 80001,
ARBITRUM_GOERLI = 421613,
}

interface TokenInfo {
Expand All @@ -29,6 +30,7 @@ export const nativeTokenAddress = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
export interface TokenAddresses {
[ChainID.GOERLI]: Record<TokenName, TokenInfo>;
[ChainID.MUMBAI]: Record<TokenName, TokenInfo>;
[ChainID.ARBITRUM_GOERLI]: Record<TokenName, TokenInfo>;
}

export const tokenAddresses: TokenAddresses = {
Expand All @@ -43,12 +45,19 @@ export const tokenAddresses: TokenAddresses = {
[TokenName.USDA2]: { address: '0x203fa10731d98444fD59DA46705321080bA99824', decimals: 6 },
[TokenName.USDB]: { address: '0x2D6d85C69e92F3008d9f06Ddf8Bac054783687B4', decimals: 8 },
[TokenName.USDC]: { address: '0xb18059aA6483bA71D6d3DfAbaD53616b00EA2ABA', decimals: 18 }
}
};
},
[ChainID.ARBITRUM_GOERLI]: {
[TokenName.USDA1]: { address: '0x11900998de6b0C32F0bB148c6865635dfc28A528', decimals: 6 },
[TokenName.USDA2]: { address: '0x889b795C64CdA1E9fAC1fA623E7F82A73306b690', decimals: 6 },
[TokenName.USDB]: { address: '0x7C96ab4B90d59CE5e51f673242651018a4432672', decimals: 8 },
[TokenName.USDC]: { address: '0xe47a4524ad3142dE28F2F8F88b4317a439Ea89a9', decimals: 18 }
},
};

export const nativeTokenAddresses = {
[ChainID.GOERLI] : '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
[ChainID.MUMBAI]: '0x0000000000000000000000000000000000001010'
[ChainID.MUMBAI]: '0x0000000000000000000000000000000000001010',
[ChainID.ARBITRUM_GOERLI] : '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',

}

Expand Down
12 changes: 5 additions & 7 deletions scripts/Gasless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export const transferErc20Tokens = async () => {
}
}
}

const resultSet = await aarcSDK.executeMigrationGasless({
senderSigner: signer,
receiverAddress: "0x786E6045eacb96cAe0259cd761e151b68B85bdA7",
Expand All @@ -79,7 +78,8 @@ export const transferErc20Tokens = async () => {
typeof result !== 'object' ||
!('tokenAddress' in result) ||
!('amount' in result) ||
result.message !== 'Transaction Successful' ||
result.message !== 'Transaction sent' &&
result.message !== 'Token Permit tx Sent' ||
!result.txHash ||
!result.amount
) {
Expand Down Expand Up @@ -127,7 +127,7 @@ export const transferFullNativeOnly = async () => {
const resultSet = await aarcSDK.executeMigrationGasless({
senderSigner: signer,
receiverAddress: '0x786E6045eacb96cAe0259cd761e151b68B85bdA7',
transferTokenDetails: [{tokenAddress: '0x0000000000000000000000000000000000001010', amount: BigNumber.from(1000)}],
transferTokenDetails: [{ tokenAddress: '0x0000000000000000000000000000000000001010', amount: BigNumber.from(1000) }],
gelatoApiKey: GELATO_API_KEY
})
console.log('ResultSet ', resultSet);
Expand All @@ -138,14 +138,13 @@ export const transferFullNativeOnly = async () => {
typeof result !== 'object' ||
!('tokenAddress' in result) ||
!('amount' in result) ||
result.message !== 'Native transfer successful' ||
result.message !== 'Native transfer tx sent' ||
!result.txHash ||
!result.amount
) {
throw new Error('Transfer Native Token Case Failed');
}
}


}
} else {
Expand Down Expand Up @@ -192,7 +191,6 @@ export const transferNftsOnly = async () => {
ERC721_ABI,
signer,
);

const ts = (await tokenContract.totalSupply()).sub(1)
console.log('nft total supply is', ts.toString())

Expand All @@ -212,7 +210,7 @@ export const transferNftsOnly = async () => {
const resultSet = await aarcSDK.executeMigrationGasless({
senderSigner: signer,
receiverAddress: '0x786E6045eacb96cAe0259cd761e151b68B85bdA7',
transferTokenDetails: [{tokenAddress: MUMBAI_NFT_ADDRESS}],
transferTokenDetails: [{ tokenAddress: MUMBAI_NFT_ADDRESS }],
gelatoApiKey: GELATO_API_KEY
})
console.log('ResultSet ', resultSet);
Expand Down
4 changes: 2 additions & 2 deletions scripts/NonGasless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const transferErc20Tokens = async () => {
typeof result !== 'object' ||
!('tokenAddress' in result) ||
!('amount' in result) ||
result.message !== 'Token transfer successful' ||
result.message !== 'Token transfer tx sent' ||
!result.txHash ||
!result.amount
) {
Expand Down Expand Up @@ -136,7 +136,7 @@ export const transferFullNativeOnly = async () => {
typeof result !== 'object' ||
!('tokenAddress' in result) ||
!('amount' in result) ||
result.message !== 'Native transfer successful' ||
result.message !== 'Native transfer tx sent' ||
!result.txHash ||
!result.amount
) {
Expand Down
66 changes: 32 additions & 34 deletions src/AarcSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
PERMIT2_CONTRACT_ADDRESS,
GELATO_RELAYER_ADDRESS,
COVALENT_TOKEN_TYPES,
nativeTokenAddresses,
gasTokenAddresses,
} from './utils/Constants';
import {
BatchTransferPermitDto,
Expand Down Expand Up @@ -63,7 +63,7 @@ class AarcSDK {
if (Object.values(ChainId).includes(chainId)) {
this.chainId = chainId;
} else {
throw new Error('Invalid chain id');
throw new Error('Unsupported chain id');
}
this.apiKey = apiKey;
this.ethersProvider = new ethers.providers.JsonRpcProvider(rpcUrl);
Expand Down Expand Up @@ -151,10 +151,10 @@ class AarcSDK {

if (tokenAddresses && tokenAddresses.length > 0) {
const isExist = tokenAddresses.find(
(token) => token === nativeTokenAddresses[this.chainId as ChainId],
(token) => token === gasTokenAddresses[this.chainId as ChainId],
);
if (!isExist) {
tokenAddresses.push(nativeTokenAddresses[this.chainId as ChainId]);
tokenAddresses.push(gasTokenAddresses[this.chainId as ChainId]);
}
}

Expand Down Expand Up @@ -303,7 +303,7 @@ class AarcSDK {
tokenAddress: tx.tokenAddress,
amount: tx.amount,
tokenId: tx.tokenId,
message: 'Nft transfer successful',
message: 'Nft transfer tx sent',
txHash: typeof txHash === 'string' ? txHash : '',
});
/* eslint-disable @typescript-eslint/no-explicit-any */
Expand All @@ -328,7 +328,7 @@ class AarcSDK {
response.push({
tokenAddress: tx.tokenAddress,
amount: tx.amount,
message: 'Token transfer successful',
message: 'Token transfer tx sent',
txHash: typeof txHash === 'string' ? txHash : '',
});
} catch (error: any) {
Expand All @@ -354,7 +354,7 @@ class AarcSDK {
response.push({
tokenAddress: tx.tokenAddress,
amount: tx.amount,
message: 'Native transfer successful',
message: 'Native transfer tx sent',
txHash: typeof txHash === 'string' ? txHash : '',
});
} catch (error: any) {
Expand Down Expand Up @@ -397,10 +397,10 @@ class AarcSDK {

if (tokenAddresses && tokenAddresses.length > 0) {
const isExist = tokenAddresses.find(
(token) => token === nativeTokenAddresses[this.chainId as ChainId],
(token) => token === gasTokenAddresses[this.chainId as ChainId],
);
if (!isExist) {
tokenAddresses.push(nativeTokenAddresses[this.chainId as ChainId]);
tokenAddresses.push(gasTokenAddresses[this.chainId as ChainId]);
}
}

Expand Down Expand Up @@ -463,6 +463,14 @@ class AarcSDK {
transactions,
owner,
receiverAddress,
true,
);

// filter out tokens that have already given allowance
const permit2TransferableTokens = erc20Tokens.filter(
(balanceObj) =>
BigNumber.from(balanceObj.permit2Allowance).gt(BigNumber.from(0)) ||
BigNumber.from(balanceObj.permit2Allowance).eq(BigNumber.from(-1)),
);

// Filtering out tokens to do permit transaction
Expand All @@ -472,7 +480,7 @@ class AarcSDK {
BigNumber.from(balanceObj.permit2Allowance).eq(BigNumber.from(0)),
);
Logger.log('permittedTokens ', permittedTokens);
permittedTokens.map(async (token) => {
const permitResponse = permittedTokens.map(async (token) => {
const permitDto: PermitDto = {
signer: senderSigner,
chainId: this.chainId,
Expand All @@ -492,16 +500,16 @@ class AarcSDK {
taskId,
};
const txStatus = await getGelatoTransactionStatus(gelatoTxStatusDto);
if (txStatus) {
if (typeof txStatus === 'string') {
permit2TransferableTokens.push(token);
}
response.push({
tokenAddress: token.token_address,
amount: token.balance,
message:
typeof txStatus === 'string'
? 'Token Permit Successful'
: 'Token Permit Failed',
? 'Token Permit tx Sent'
: 'Token Permit Tx Failed',
txHash: typeof txStatus === 'string' ? txStatus : '',
});
} catch (error: any) {
Expand All @@ -521,24 +529,14 @@ class AarcSDK {
}
});

// filter out tokens that have already given allowance
const permit2TransferableTokens = erc20Tokens.filter(
(balanceObj) =>
BigNumber.from(balanceObj.permit2Allowance).gt(BigNumber.from(0)) ||
BigNumber.from(balanceObj.permit2Allowance).eq(BigNumber.from(-1)),
);

// Merge permittedTokens and permit2TransferableTokens
const batchPermitTransaction = permittedTokens.concat(
permit2TransferableTokens,
);
await Promise.all(permitResponse);

if (batchPermitTransaction.length === 1) {
if (permit2TransferableTokens.length === 1) {
const singleTransferPermitDto: SingleTransferPermitDto = {
signer: senderSigner,
chainId: this.chainId,
spenderAddress: GELATO_RELAYER_ADDRESS,
tokenData: batchPermitTransaction[0],
tokenData: permit2TransferableTokens[0],
};
const permit2SingleContract = new Contract(
PERMIT2_CONTRACT_ADDRESS,
Expand Down Expand Up @@ -583,8 +581,8 @@ class AarcSDK {
amount: permitTransferFrom.permitted.amount,
message:
typeof txStatus === 'string'
? 'Transactions Successful'
: 'Transactions Failed',
? 'Transaction sent'
: 'Transaction Failed',
txHash: typeof txStatus === 'string' ? txStatus : '',
});
} catch (error: any) {
Expand All @@ -596,7 +594,7 @@ class AarcSDK {
error,
);
}
} else if (batchPermitTransaction.length > 1) {
} else if (permit2TransferableTokens.length > 1) {
const permit2BatchContract = new Contract(
PERMIT2_CONTRACT_ADDRESS,
PERMIT2_BATCH_TRANSFER_ABI,
Expand All @@ -607,7 +605,7 @@ class AarcSDK {
signer: senderSigner,
chainId: this.chainId,
spenderAddress: GELATO_RELAYER_ADDRESS,
tokenData: batchPermitTransaction,
tokenData: permit2TransferableTokens,
};
const permitData = await this.permitHelper.getBatchTransferPermitData(
batchTransferPermitDto,
Expand Down Expand Up @@ -654,7 +652,7 @@ class AarcSDK {
amount: token.amount,
message:
typeof txStatus === 'string'
? 'Transaction Successful'
? 'Transaction sent'
: 'Transaction Failed',
txHash: typeof txStatus === 'string' ? txStatus : '',
});
Expand Down Expand Up @@ -730,7 +728,7 @@ class AarcSDK {
tokenAddress: tx.tokenAddress,
amount: tx.amount,
tokenId: tx.tokenId,
message: 'Nft transfer successful',
message: 'Nft transfer tx sent',
txHash: typeof txHash === 'string' ? txHash : '',
});
} catch (error: any) {
Expand All @@ -754,7 +752,7 @@ class AarcSDK {
response.push({
tokenAddress: tx.tokenAddress,
amount: tx.amount,
message: 'Token transfer successful',
message: 'Token transfer tx sent',
txHash: typeof txHash === 'string' ? txHash : '',
});
} catch (error: any) {
Expand All @@ -780,7 +778,7 @@ class AarcSDK {
response.push({
tokenAddress: tx.tokenAddress,
amount: tx.amount,
message: 'Native transfer successful',
message: 'Native transfer tx sent',
txHash: typeof txHash === 'string' ? txHash : '',
});
} catch (error: any) {
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/EstimatorHelper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BigNumber, ethers } from 'ethers';
import { Logger } from '../utils/Logger';
import { GAS_UNITS, nativeTokenAddresses } from '../utils/Constants';
import { GAS_UNITS, gasTokenAddresses } from '../utils/Constants';
import { ERC20_ABI } from '../utils/abis/ERC20.abi';
import { PERMIT2_BATCH_TRANSFER_ABI } from '../utils/abis/Permit2BatchTransfer.abi';
import { ChainId } from '../utils/ChainTypes';
Expand All @@ -20,7 +20,7 @@ export const calculateTotalGasNeeded = async (

for (const transaction of transactions) {
try {
if (transaction.to !== nativeTokenAddresses[chainId as ChainId]) {
if (transaction.to !== gasTokenAddresses[chainId as ChainId]) {
if (transaction.type === 'permitbatch') {
const contract = new ethers.Contract(
transaction.tokenAddress,
Expand Down Expand Up @@ -58,7 +58,7 @@ export const calculateTotalGasNeeded = async (
const tx = {
from: transaction.from,
to:
transaction.to !== nativeTokenAddresses[chainId as ChainId]
transaction.to !== gasTokenAddresses[chainId as ChainId]
? transaction.tokenAddress
: transaction.to,
data: transaction.data,
Expand Down
Loading

0 comments on commit fa48b0a

Please sign in to comment.