Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/PRO-305-int…
Browse files Browse the repository at this point in the history
…egration-of-stargate-for-bridging
  • Loading branch information
lbw33 committed Jul 12, 2023
2 parents d363d1f + 789364e commit d272cc6
Show file tree
Hide file tree
Showing 113 changed files with 7,184 additions and 1,597 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
install:
working_directory: ~/etherspot-sdk
docker:
- image: circleci/node:14.17.0
- image: cimg/node:14.21.3
auth:
username: $DOCKERHUB_USER
password: $DOCKERHUB_PASSWORD
Expand All @@ -33,7 +33,7 @@ jobs:
publish:
working_directory: ~/etherspot-sdk
docker:
- image: circleci/node:14.17.0
- image: cimg/node:14.21.3
auth:
username: $DOCKERHUB_USER
password: $DOCKERHUB_PASSWORD
Expand Down
Binary file added .github/etherspot_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed .github/logo.png
Binary file not shown.
24 changes: 24 additions & 0 deletions .github/workflows/check-npm-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Check if package version is updated

on:
pull_request:
branches:
- master
jobs:
start:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Check if version has been updated
id: check
uses: EndBug/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
file-name: ./package.json
- name: Log when changed
if: steps.check.outputs.changed == 'true'
run: 'echo "Yayy!! Version change found in commit ${{ steps.check.outputs.commit }}! New version: ${{ steps.check.outputs.version }} (${{ steps.check.outputs.type }})"'
- name: Log when unchanged
if: steps.check.outputs.changed == 'false'
run: echo "No version change :/ Please update version in package.json!" && exit 1
6 changes: 3 additions & 3 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add - <<< "${{ secrets.SSH_KEY_DOCS }}"
ssh-add - <<< "${{ secrets.SSH_MACHINE_KEY_DOCS }}"
- name: Setup git
run: |
git config --global user.email "[email protected]"
git config --global user.name "ETHERspot"
git config --global user.email "[email protected]"
git config --global user.name "EtherspotBOT"
- name: Checkout
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-linter-and-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup node.js
uses: actions/setup-node@v1
with:
node-version: 10.x
node-version: 12.x

- name: Determine npm cache directory
id: npm-cache
Expand Down
34 changes: 18 additions & 16 deletions .github/workflows/run-static-code-anlayzer.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
name: Static code analyzer
name: CodeQL scan

on:
push:
branches: [ master, develop ]
branches: [master]
pull_request:
branches: [ master, develop ]
branches: [master]

jobs:
njsscan:
analyze:
runs-on: ubuntu-latest
name: Run static code analyzer

steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: nodejsscan scan
id: njsscan
uses: ajinabraham/njsscan-action@master
with:
args: 'src --sarif --output results.sarif || true'
- name: Upload njsscan report
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: results.sarif
- name: Checkout repository
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8

- name: Initialize CodeQL
uses: github/codeql-action/init@807578363a7869ca324a79039e6db9c843e0e100
with:
queries: security-and-quality
languages: javascript

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@807578363a7869ca324a79039e6db9c843e0e100
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run lint
npm run test
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run build
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@
![MIT licensed][license-image]

<a href="https://www.etherspot.io">
<img src=".github/logo.png" width="100"/>
<img src=".github/etherspot_logo.png" width="100"/>
</a>


Etherspot is a blockchain development framework for EVM-compatible chains that creates direct state channel bridges to provide a seamless user experience across chains and wallets.

With just one deposit you’re able to onboard your users to the entire multichain world.

Developers can use the Buidler and TransactionKit tools to easily include Etherspot features into their dapps.

For more powerful but complex uses, developers can dive deeper into the SDK and explore a number of custom use cases.

More information at [etherspot.io](https://www.etherspot.io)

## Resources

* [playground](https://try.etherspot.dev)
* [documentation](https://docs.etherspot.dev)
* [examples](https://github.com/etherspot/etherspot-sdk/tree/develop/examples)
* [Playground](https://try.etherspot.dev)
* [BUIDLer](https://buidler.etherspot.io/)
* [TransactionKit](https://etherspot.io/transactionkit/)
* [Documentation](https://docs.etherspot.dev)
* [Examples](https://github.com/etherspot/etherspot-sdk/tree/develop/examples)

## Installation

Expand Down Expand Up @@ -66,6 +72,10 @@ main().catch(console.error);

notification of transactions is not available for fuse

## Transaction History on Klaytn

History of transactions would be incomplete only on Klaytn Network due to lack of resources for fetching the required data


## License

Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ $ npm run <example name> # eg. 01-session
* [delayed transactions](./src/14-delayed-transactions.ts) -- allow to automatically delay account transactions
* [external contracts](./src/16-cross-chain-quote.ts) -- execute cross chain transaction
* [SuperFluids Create Stream](./src/17-superFluids-createStream.ts) -- create stream of superTokens
* [name resolution](./src/22-name-resolution.ts) -- resolve domain name of ENS, Unstoppable Domains and FIO protocol
14 changes: 12 additions & 2 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,19 @@
"13-transactions": "../node_modules/.bin/ts-node ./src/13-transactions",
"14-delayed-transactions": "../node_modules/.bin/ts-node ./src/14-delayed-transactions",
"15-topup-fuctions": "../node_modules/.bin/ts-node ./src/15-topup-fuctions",
"16-cross-chain-quote": "../node_modules/.bin/ts-node ./src/16-cross-chain-quote.ts",
"16-cross-chain-quotes": "../node_modules/.bin/ts-node ./src/16-cross-chain-quotes.ts",
"17-superFluids-createStream": "../node_modules/.bin/ts-node ./src/17-superFluids-createStream.ts",
"18-cross-chain-stream": "../node_modules/.bin/ts-node ./src/18-cross-chain-stream.ts"
"18-cross-chain-stream": "../node_modules/.bin/ts-node ./src/18-cross-chain-stream.ts",
"21-exchange-rates": "../node_modules/.bin/ts-node ./src/21-exchange-rates.ts",
"22-name-resolution": "../node_modules/.bin/ts-node ./src/22-name-resolution.ts",
"24-account-investments": "../node_modules/.bin/ts-node ./src/24-account-investments.ts",
"25-token-details": "../node_modules/.bin/ts-node ./src/25-token-details.ts",
"26-historical-token-price" : "../node_modules/.bin/ts-node ./src/26-historical-token-price.ts",
"27-pools-activity" : "../node_modules/.bin/ts-node ./src/27-pools-activity.ts",
"28-number-of-transactions" : "../node_modules/.bin/ts-node ./src/28-number-of-transactions.ts",
"29-trading-history" : "../node_modules/.bin/ts-node ./src/29-trading-history.ts",
"30-market-details" : "../node_modules/.bin/ts-node ./src/30-market-details.ts",
"31-net-curve-balances" : "../node_modules/.bin/ts-node ./src/31-net-curve-balances.ts"
},
"dependencies": {
"dotenv": "16.0.1"
Expand Down
89 changes: 48 additions & 41 deletions examples/src/16-cross-chain-quotes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { BigNumberish, utils } from 'ethers';
import { ContractNames, getContractAbi } from '@etherspot/contracts';
import { EnvNames, NetworkNames, Sdk, NETWORK_NAME_TO_CHAIN_ID, BridgingQuotes, CrossChainServiceProvider } from '../../src';
import {
EnvNames,
NetworkNames,
Sdk,
NETWORK_NAME_TO_CHAIN_ID,
BridgingQuotes,
CrossChainServiceProvider,
} from '../../src';
import { logger } from './common';
import * as dotenv from 'dotenv';
import { TransactionRequest } from '@ethersproject/abstract-provider';
Expand Down Expand Up @@ -48,9 +55,9 @@ async function main(): Promise<void> {
const fromAmount = utils.parseUnits('1', 6); // 10 USDC

/*
* Optional parameter - serviceProvider
* Will return quotes from all services provided if not specified
*/
* Optional parameter - serviceProvider
* Will return quotes from all services provided if not specified
*/
const quoteRequestPayload = {
fromChainId: fromChainId,
toChainId: toChainId,
Expand All @@ -65,45 +72,45 @@ async function main(): Promise<void> {
console.log('Quotes');
logger.log('Quotes: ', quotes);

if(quotes.items.length > 0 ) {
// Select the first quote
const quote = quotes.items[0];
logger.log('Quote Selected: ', quote);

const tokenAddres = quote.estimate.data.fromToken.address;
const approvalAddress = quote.approvalData.approvalAddress;
const amount = quote.approvalData.amount;

// Build the approval transaction request
const abi = getContractAbi(ContractNames.ERC20Token);
const erc20Contract = sdk.registerContract<ERC20Contract>('erc20Contract', abi, tokenAddres);
const approvalTransactionRequest: TransactionRequest = erc20Contract.encodeApprove(approvalAddress, amount);
logger.log('Approval transaction request', approvalTransactionRequest);
await sdk.clearGatewayBatch();
// Batch the approval transaction
logger.log(
'gateway batch approval transaction',
await sdk.batchExecuteAccountTransaction({
to: approvalTransactionRequest.to,
data: approvalTransactionRequest.data,
value: approvalTransactionRequest.value,
}),
);

// Batch the cross chain transaction
const { to, value, data }: TransactionRequest = quote.transaction;
logger.log(
'gateway batch transfer token transaction',
await sdk.batchExecuteAccountTransaction({ to, data: data, value }),
);

const estimatedGas = await sdk.estimateGatewayBatch();
// Estimate and submit the transactions to the Gateway
logger.log('estimated batch', utils.formatEther(estimatedGas.estimation.feeAmount));
logger.log('submitted batch', await sdk.submitGatewayBatch());
if (quotes.items.length > 0) {
// Select the first quote
const quote = quotes.items[0];
logger.log('Quote Selected: ', quote);

const tokenAddres = quote.estimate.data.fromToken.address;
const approvalAddress = quote.approvalData.approvalAddress;
const amount = quote.approvalData.amount;

// Build the approval transaction request
const abi = getContractAbi(ContractNames.ERC20Token);
const erc20Contract = sdk.registerContract<ERC20Contract>('erc20Contract', abi, tokenAddres);
const approvalTransactionRequest: TransactionRequest = erc20Contract.encodeApprove(approvalAddress, amount);
logger.log('Approval transaction request', approvalTransactionRequest);
await sdk.clearGatewayBatch();
// Batch the approval transaction
logger.log(
'gateway batch approval transaction',
await sdk.batchExecuteAccountTransaction({
to: approvalTransactionRequest.to,
data: approvalTransactionRequest.data,
value: approvalTransactionRequest.value,
}),
);

// Batch the cross chain transaction
const { to, value, data }: TransactionRequest = quote.transaction;
logger.log(
'gateway batch transfer token transaction',
await sdk.batchExecuteAccountTransaction({ to, data: data, value }),
);

const estimatedGas = await sdk.estimateGatewayBatch();
// Estimate and submit the transactions to the Gateway
logger.log('estimated batch', utils.formatEther(estimatedGas.estimation.feeAmount));
logger.log('submitted batch', await sdk.submitGatewayBatch());
}
}

main()
.catch(logger.error)
.finally(() => process.exit());
.finally(() => process.exit());
44 changes: 44 additions & 0 deletions examples/src/19-exchange-using-fee-token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { BigNumber, Wallet, constants, ethers } from 'ethers';
import { EnvNames, NetworkNames, Sdk } from '../../src';
import { logger } from './common';

async function main(): Promise<void> {
const wallet = Wallet.createRandom();
const sdk = new Sdk(wallet, {
env: EnvNames.MainNets,
networkName: NetworkNames.Matic,
});

await sdk.computeContractAccount();
const exchangeSupportedAssets = await sdk.getExchangeSupportedAssets({ page: 1, limit: 100 });
logger.log('found exchange supported assets', exchangeSupportedAssets.items.length);

// NOTE: use ethers.constants.AddressZero for ETH
const fromTokenAddress = '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174'; // USDC
const toTokenAddress = constants.AddressZero; // ETH
const fromAmount = ethers.utils.parseUnits('5', 6); // 5 USDC

const offers = await sdk.getExchangeOffers({
fromTokenAddress,
toTokenAddress,
fromAmount: BigNumber.from(fromAmount),
});
console.log('offers: ', offers);
const offer = offers[0]; // Selected the first offer that we got
console.log(
'selected exchange offers',
offer,
offer.transactions,
);
await sdk.clearGatewayBatch();
await sdk.batchExecuteAccountTransaction(offer.transactions[0]);
await sdk.batchExecuteAccountTransaction(offer.transactions[1]);
const estimation = await sdk.estimateGatewayBatch({ feeToken: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174' }); // pay gas using USDC
console.log('estimate: ', estimation);
await sdk.submitGatewayBatch();

}

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

0 comments on commit d272cc6

Please sign in to comment.