Skip to content

Commit

Permalink
chore: accept coin symbols in both uppercase and lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
gurukishore111 committed Mar 20, 2024
1 parent 3be9006 commit 429cb74
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 73 deletions.
68 changes: 56 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,34 @@ const checkUserRes = await client.checkInternalTransferUserExists(
)
```

### Setting Allowance

Granting permission for token spending enables transactions on Ethereum and other chains.

> Supported EVM cross-chain networks: 'ETHEREUM', 'POLYGON', 'OPTIMISM', 'ARBITRUM', 'LINEA', 'SCROLL', 'MODE'.
```js
// Note: Please use ethers version 5.5.3.
import { Wallet, ethers } from 'ethers'

const provider = new ethers.providers.JsonRpcProvider(
process.env.RPC_PROVIDER, // Use 'Polygon Mumbai' for the testnet and 'Polygon mainnet' for the mainnet.
)

const signer = new Wallet(privateKey, provider)

const res = await client.setAllowance(
'usdc', // Enter the coin symbol.
signer,
'SCROLL', // Enter the network for which you want to grant allowance.
// This argument is optional; if you pass the argument, the gasLimit and gasPrice will be overridden while executing the transaction..
// {
// gasLimit: '',
// gasPrice: '',
// },
)
```

### Deposit

#### Ethereum Deposit
Expand Down Expand Up @@ -477,20 +505,28 @@ const depositRes = await client.depositFromEthereumNetworkWithStarkKey(
)
```

#### Polygon Deposit
#### Cross-Chain Deposit

There are two ways to make a deposit on the Cross-chain:

There are two ways to make a deposit on the Polygon network:
> Supported EVM cross-chain networks - 'POLYGON' | 'OPTIMISM' | 'ARBITRUM' | 'LINEA' | 'SCROLL' | 'MODE'
#### 1. Using ETH Private Key and RPC URL:

In this method, you will use an ETH private key and an RPC URL to execute a Polygon deposit. You'll also need to create an RPC URL using services like Infura, Alchemy, etc. Here's the code snippet for this method:
In this method, you will use an ETH private key and an RPC URL to execute a Cross-Chain deposit. You'll also need to create an RPC URL using services like Infura, Alchemy, etc. Here's the code snippet for this method:

```javascript
const depositRes = await client.depositFromPolygonNetwork(
const depositRes = await client.crossChainDeposit(
process.env.RPC_PROVIDER as string, // Use 'Polygon Mumbai' for the testnet and 'Polygon mainnet' for the mainnet.
privateKey, // Your ETH private key.
'btc', // Enter the coin symbol.
0.00001, // Enter the amount you want to deposit.
'usdt', // Enter the coin symbol.
1, // Enter the amount you want to deposit.
'SCROLL' // Enter the network you want to deposit.
// This argument is optional; if you pass the argument, the gasLimit and gasPrice will be overridden while executing the transaction.
{
gasLimit: '',
gasPrice: '',
},
);
```

Expand All @@ -511,8 +547,14 @@ const signer = new Wallet(privateKey, provider)
const depositPolygonRes = await client.depositFromPolygonNetworkWithSigner(
signer, // The signer created above.
provider, // The provider created above.
'btc', // Enter the coin symbol.
'usdc', // Enter the coin symbol.
0.00001, // Enter the amount you want to deposit.
'SCROLL' // Enter the network you want to deposit.
// This argument is optional; if you pass the argument, the gasLimit and gasPrice will be overridden while executing the transaction.
{
gasLimit: '',
gasPrice: '',
},
)
```

Expand All @@ -522,7 +564,7 @@ To get the deposit history, you can use the following code:

```javascript
const depositsList = await client.listDeposits({
network: 'ETHEREUM', // Network for which you want to list the deposit history. Allowed networks are ETHEREUM & POLYGON
network: 'ETHEREUM', // Specify the network for which you want to list the deposit history. Allowed networks include 'ETHEREUM', 'POLYGON', 'OPTIMISM', 'ARBITRUM', 'LINEA', 'SCROLL', and 'MODE'.
page: 2, // This is an optional field
limit: 1, // This is an optional field
})
Expand Down Expand Up @@ -575,7 +617,7 @@ const fastWithdrawalRes = await client.fastWithdrawal(
keyPair, // The keyPair created above
0.0001, // Enter the amount you want to deposit
'usdc', // Enter the coin symbol
'ETHEREUM', // Allowed networks are POLYGON & ETHEREUM
'ETHEREUM', // Allowed networks include 'ETHEREUM', 'POLYGON', 'OPTIMISM', 'ARBITRUM', 'LINEA', 'SCROLL', and 'MODE'
)

//Get a list of fast withdrawals
Expand All @@ -584,15 +626,17 @@ const fastwithdrawalsList = await client.listFastWithdrawals({
})
```

#### Polygon withdrawal
#### Cross-chain withdrawal

> Supported EVM cross-chain networks - 'POLYGON' | 'OPTIMISM' | 'ARBITRUM' | 'LINEA' | 'SCROLL' | 'MODE'
On the Polygon network, we only support fast withdrawals.
On the cross-chain withdrawal network, we only support fast withdrawals.

```javascript
const fastWithdrawalRes = await client.fastWithdrawal(
keyPair, // The keyPair created above
0.0001, // Enter the amount you want to deposit
'usdc', // Enter the coin symbol
'POLYGON', // Allowed networks are POLYGON & ETHEREUM
'POLYGON', // Enter the network you want to withdraw.
)
```
54 changes: 27 additions & 27 deletions example/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ const approveAllowance = async () => {
const signer = new Wallet(privateKey, provider)
// Supported cross-chain networks - 'POLYGON' | 'OPTIMISM' | 'ARBITRUM' | 'LINEA' | 'SCROLL' | 'MODE'
const res = await client.setAllowance(
'usdc',
'btc',
signer,
'MODE',
'POLYGON',
// This argument is optional; if you pass the argument, the gasLimit and gasPrice will be overridden.
{
gasLimit: '',
gasPrice: '',
},
// {
// gasLimit: '',
// gasPrice: '',
// },
)

console.log({ res }, 'allowance')
Expand Down Expand Up @@ -286,14 +286,14 @@ const crossDepositAndWithdrawal = async () => {
const deposit = await client.crossChainDeposit(
process.env.RPC_PROVIDER as string,
privateKey,
'usdc',
'BTC',
'1',
'MODE',
'POLYGON',
// This argument is optional; if you pass the argument, the gasLimit and gasPrice will be overridden.
{
gasLimit: '',
gasPrice: '',
},
// {
// gasLimit: '',
// gasPrice: '',
// },
)

// Deposit with signer
Expand All @@ -302,8 +302,8 @@ const crossDepositAndWithdrawal = async () => {
// provider,
// 'usdc',
// '1',
// 'MODE'
// );
// 'SCROLL',
// )

// Get a list of deposits
const depositList = await client.listDeposits({
Expand All @@ -313,24 +313,24 @@ const crossDepositAndWithdrawal = async () => {
})

// Fast withdrawal
const fastWithdrawalRes = await client.fastWithdrawal(
keyPair,
12,
'usdc',
'MODE',
)
// const fastWithdrawalRes = await client.fastWithdrawal(
// keyPair,
// 12,
// 'usdt',
// 'MODE',
// )

// Get a list of fast withdrawals
const fastwithdrawalsList = await client.listFastWithdrawals({
page: 1, // This is an optional field
network: 'MODE', // This is an optional field
})
// const fastwithdrawalsList = await client.listFastWithdrawals({
// page: 1, // This is an optional field
// network: 'MODE', // This is an optional field
// })

console.log({
crossDeposit: deposit,
depositList,
fastwithdrawalsList,
fastWithdrawalRes,
// fastwithdrawalsList,
// fastWithdrawalRes,
})
} catch (e) {
// Error: AuthenticationError | AxiosError
Expand All @@ -342,7 +342,7 @@ const crossDepositAndWithdrawal = async () => {
}
}
}
// crossDepositAndWithdrawal()
crossDepositAndWithdrawal()

const internalTransfers = async () => {
// load your privateKey and walletAddress
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"typescript": "^4.7.4"
},
"dependencies": {
"@ethersproject/bignumber": "^5.7.0",
"axios": "^1.3.4",
"bn.js": "^5.2.1",
"elliptic": "^6.5.4",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 429cb74

Please sign in to comment.