-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from etherspot/add-examples-for-sdk
First Version of the sdk
- Loading branch information
Showing
416 changed files
with
55,047 additions
and
14,559 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Deployment Costs | ||
|
||
## Average Gas Costs (per transaction) | ||
|
||
| Transaction | Gas Cost (Avg) | | ||
|--------------|----------------| | ||
| Wallet deployment | 180000 gwei | | ||
| Native token transfer | 102344 gwei | | ||
| ERC20 token transfer | 127683 gwei | | ||
| Token swap (Uniswap v3) | 308041 gwei (swap + approval: 185648 + 122393) | | ||
|
||
## Costs By Chain (per transaction) | ||
|
||
| Ethereum | Standard (53 gwei) | Fast (57 gwei) | | ||
|----------|--------------------|----------------| | ||
| Wallet deployment | $19.32 | $20.25 | | ||
| Native token transfer | $10.07 | $10.83 | | ||
| ERC20 token transfer | $12.61 | $13.55 | | ||
| Token swap (Uniswap v3) | $30.27 | $32.67 | | ||
|
||
| Polygon | Low (425.6 gwei) | High (426.6 gwei) | | ||
|----------|--------------------|----------------| | ||
| Wallet deployment | $0.09 | $0.09 | | ||
| Native token transfer | $0.05 | $0.05 | | ||
| ERC20 token transfer | $0.06 | $0.06 | | ||
| Token swap (Uniswap v3) | $0.14 | $0.14 | | ||
|
||
| Binance Smart Chain | Low (3 gwei) | High (3 gwei) | | ||
|----------|--------------------|----------------| | ||
| Wallet deployment | $0.19 | $0.19 | | ||
| Native token transfer | $0.11 | $0.11 | | ||
| ERC20 token transfer | $0.13 | $0.13 | | ||
| Token swap (Uniswap v3) | $0.31 | $0.31 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
WALLET_PRIVATE_KEY= | ||
|
||
RPC_PROVIDER_URL= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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) }) | ||
|
||
// get EtherspotWallet address... | ||
const address: string = await primeSdk.getCounterFactualAddress(); | ||
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address: ${address}`); | ||
} | ||
|
||
main() | ||
.catch(console.error) | ||
.finally(() => process.exit()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { ethers } from 'ethers'; | ||
import { PrimeSdk } from '../src'; | ||
import { printOp } from '../src/sdk/common/OperationUtils'; | ||
|
||
const recipient: string = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address | ||
const value: string = '0.01'; // transfer value | ||
|
||
async function main() { | ||
// initializating sdk... | ||
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID) }) | ||
|
||
console.log('address: ', primeSdk.state.walletAddress) | ||
|
||
// get address of EtherspotWallet... | ||
const address: string = await primeSdk.getCounterFactualAddress(); | ||
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address: ${address}`); | ||
|
||
// clear the transaction batch | ||
await primeSdk.clearUserOpsFromBatch(); | ||
|
||
// add transactions to the batch | ||
const transactionBatch = await primeSdk.addUserOpsToBatch({to: recipient, value: ethers.utils.parseEther(value)}); | ||
console.log('transactions: ', transactionBatch); | ||
|
||
// get balance of the account address | ||
const balance = await primeSdk.getNativeBalance(); | ||
|
||
console.log('balances: ', balance); | ||
|
||
// sign transactions added to the batch | ||
const op = await primeSdk.sign(); | ||
console.log(`Signed UserOp: ${await printOp(op)}`); | ||
|
||
// sending to the bundler... | ||
const uoHash = await primeSdk.send(op); | ||
console.log(`UserOpHash: ${uoHash}`); | ||
|
||
// get transaction hash... | ||
console.log('Waiting for transaction...'); | ||
const txHash = await primeSdk.getUserOpReceipt(uoHash); | ||
console.log('\x1b[33m%s\x1b[0m', `Transaction hash: ${txHash}`); | ||
} | ||
|
||
main() | ||
.catch(console.error) | ||
.finally(() => process.exit()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ethers } from 'ethers'; | ||
import { PrimeSdk } from '../src'; | ||
import { printOp } from '../src/sdk/common/OperationUtils'; | ||
import { ERC20_ABI } from '../src/sdk/helpers/abi/ERC20_ABI'; | ||
import * as dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
// add/change these values | ||
const recipient: string = '0xD129dB5e418e389c3F7D3ae0B8771B3f76799A52'; // recipient wallet address | ||
const value: string = '0.1'; // transfer value | ||
const tokenAddress: string = '0x326C977E6efc84E512bB9C30f76E30c160eD06FB'; | ||
|
||
async function main() { | ||
// initializating sdk... | ||
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID) }) | ||
|
||
console.log('address: ', primeSdk.state.walletAddress) | ||
|
||
// get address of EtherspotWallet... | ||
const address: string = await primeSdk.getCounterFactualAddress(); | ||
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address: ${address}`); | ||
|
||
const provider = new ethers.providers.JsonRpcProvider(process.env.BUNDLER_URL) | ||
// get erc20 Contract Interface | ||
const erc20Instance = new ethers.Contract(tokenAddress, ERC20_ABI, provider); | ||
|
||
// get decimals from erc20 contract | ||
const decimals = await erc20Instance.functions.decimals(); | ||
|
||
// get transferFrom encoded data | ||
const transactionData = erc20Instance.interface.encodeFunctionData('transfer', [recipient, ethers.utils.parseUnits(value, decimals)]) | ||
|
||
// clear the transaction batch | ||
await primeSdk.clearUserOpsFromBatch(); | ||
|
||
// add transactions to the batch | ||
let userOpsBatch = await primeSdk.addUserOpsToBatch({to: tokenAddress, data: transactionData}); | ||
console.log('transactions: ', userOpsBatch); | ||
|
||
// sign transactions added to the batch | ||
const op = await primeSdk.sign(); | ||
console.log(`Signed UserOp: ${await printOp(op)}`); | ||
|
||
// sending to the bundler... | ||
const uoHash = await primeSdk.send(op); | ||
console.log(`UserOpHash: ${uoHash}`); | ||
|
||
// get transaction hash... | ||
console.log('Waiting for transaction...'); | ||
const txHash = await primeSdk.getUserOpReceipt(uoHash); | ||
console.log('\x1b[33m%s\x1b[0m', `Transaction hash: ${txHash}`); | ||
} | ||
|
||
main() | ||
.catch(console.error) | ||
.finally(() => process.exit()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { ethers } from 'ethers'; | ||
import { PrimeSdk } from '../src'; | ||
import { printOp } from '../src/sdk/common/OperationUtils'; | ||
import * as dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
// add/change these values | ||
const recipient: string = '0xD129dB5e418e389c3F7D3ae0B8771B3f76799A52'; // recipient wallet address | ||
const tokenAddress: string = '0xe55C5793a52AF819fBf3e87a23B36708E6FDd2Cc'; | ||
const tokenId = 4; | ||
|
||
async function main() { | ||
// initializating sdk... | ||
const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID) }) | ||
|
||
console.log('address: ', primeSdk.state.walletAddress) | ||
|
||
// get address of EtherspotWallet... | ||
const address: string = await primeSdk.getCounterFactualAddress(); | ||
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address: ${address}`); | ||
|
||
const erc721Interface = new ethers.utils.Interface([ | ||
'function safeTransferFrom(address _from, address _to, uint256 _tokenId)' | ||
]) | ||
|
||
const erc721Data = erc721Interface.encodeFunctionData('safeTransferFrom', [address, recipient, tokenId]); | ||
|
||
// clear the transaction batch | ||
await primeSdk.clearUserOpsFromBatch(); | ||
|
||
// add transactions to the batch | ||
let userOpsBatch = await primeSdk.addUserOpsToBatch({to: tokenAddress, data: erc721Data}); | ||
console.log('transactions: ', userOpsBatch); | ||
|
||
// sign transactions added to the batch | ||
const op = await primeSdk.sign(); | ||
console.log(`Signed UserOp: ${await printOp(op)}`); | ||
|
||
// sending to the bundler... | ||
const uoHash = await primeSdk.send(op); | ||
console.log(`UserOpHash: ${uoHash}`); | ||
|
||
// get transaction hash... | ||
console.log('Waiting for transaction...'); | ||
const txHash = await primeSdk.getUserOpReceipt(uoHash); | ||
console.log('\x1b[33m%s\x1b[0m', `Transaction hash: ${txHash}`); | ||
} | ||
|
||
main() | ||
.catch(console.error) | ||
.finally(() => process.exit()); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { ethers } from "ethers"; | ||
// @ts-ignore | ||
import config from "../../config.json"; | ||
import { PrimeSdk } from "../../../src"; | ||
import { printOp } from "../../../src/sdk/common/OperationUtils"; | ||
|
||
export default async function main( | ||
tknid: number, | ||
t: string, | ||
tkn: string, | ||
) { | ||
const primeSdk = new PrimeSdk({ privateKey: config.signingKey }, { chainId: config.chainId, rpcProviderUrl: config.rpcProviderUrl }) | ||
|
||
const address = await primeSdk.getCounterFactualAddress(); | ||
|
||
const tokenId = tknid; | ||
const tokenAddress = ethers.utils.getAddress(tkn); | ||
const to = ethers.utils.getAddress(t); | ||
console.log(`Transferring NFT ${tknid} ...`); | ||
|
||
const erc721Interface = new ethers.utils.Interface([ | ||
'function safeTransferFrom(address _from, address _to, uint256 _tokenId)' | ||
]) | ||
|
||
const erc721Data = erc721Interface.encodeFunctionData('safeTransferFrom', [address, to, tokenId]); | ||
|
||
// clear the transaction batch | ||
await primeSdk.clearUserOpsFromBatch(); | ||
|
||
|
||
await primeSdk.addUserOpsToBatch({to: tokenAddress, data: erc721Data}); | ||
console.log(`Added transaction to batch`); | ||
|
||
const op = await primeSdk.sign(); | ||
console.log(`Signed UserOp: ${await printOp(op)}`); | ||
|
||
// sending to the bundler... | ||
const uoHash = await primeSdk.send(op); | ||
console.log(`UserOpHash: ${uoHash}`); | ||
|
||
// get transaction hash... | ||
console.log('Waiting for transaction...'); | ||
const txHash = await primeSdk.getUserOpReceipt(uoHash); | ||
console.log('\x1b[33m%s\x1b[0m', `Transaction hash: ${txHash}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// @ts-ignore | ||
import config from "../../config.json"; | ||
import { PrimeSdk } from "../../../src"; | ||
|
||
export default async function main() { | ||
const primeSdk = new PrimeSdk({ privateKey: config.signingKey }, { chainId: 80001 }) | ||
const address = await primeSdk.getCounterFactualAddress(); | ||
|
||
console.log(`Etherspot address: ${address}`); | ||
} |
Oops, something went wrong.