Coder Social home page Coder Social logo

synapsecns / sdk Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 22.0 4 MB

Synapse Protocol's NodeJS SDK

Home Page: https://www.npmjs.com/package/@synapseprotocol/sdk

License: ISC License

Shell 0.99% Python 0.27% TypeScript 98.74%
nodejs ethereum blockchain sdk bridge typescript synapse crosschain

sdk's Introduction

Repository Deprecated

Note: This repository is no longer maintained and has been deprecated in favor of the new sdk. We recommend all users to transition to the new sdk for the latest updates, features, and support.

New SDK

You can find the npm package here.

Support

For support with the new repository, please open an issue on the SDK.

synapseprotocol-sdk

NPM

Tests (master) Coverage (master) Tests (dev) Coverage (dev)

Typescript SDK for the Synapse Protocol.

Usage instructions

See the Docs.

Looking to help?

Read our guidelines for contributing.

sdk's People

Contributors

abtestingalpha avatar aureliusbtc avatar blazewashere avatar bleaker0x avatar caesar0x avatar cryptomaxplanck avatar defi-moses avatar renovate-bot avatar renovate[bot] avatar trajan0x avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sdk's Issues

ESNext and CommonJS issue

My project uses commonJS but this sdk is ESNext. I am getting the following error:

...
const sdk_1 = require("@synapseprotocol/sdk");

Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/my_project/node_modules/@synapseprotocol/sdk/dist/index.js from /path/to/my_project/dist/src/bridges/synapse/utils/chainUtils.js not supported.
Instead change the require of index.js in /path/to/my_project/dist/path/to/code/file.js to a dynamic import() which is available in all CommonJS modules.

NOTE: I use nestjs 8.0.0, typescript 4.3.5

Any suggestions on this issue?

Version ^0.95.1-alpha.66 returns zero in amountToReceive

We are using your sdk version 0.95.1-alpha.66, the newest code. Your sdk returned wrong amountToReceive and bridge fee for the pair USDC <> USDC on Arbitrum to Ethererum.

Here is the code that we are using:

const SYNAPSE_BRIDGE = new Bridge.SynapseBridge({
    network: Networks.fromChainId(42161),
    provider: provider,
  });
  
 const estimate = await SYNAPSE_BRIDGE.estimateBridgeTokenOutput({
    tokenFrom: fromTokenObj,
    tokenTo: toTokenObj,
    chainIdTo: 1,
    amountFrom: 510000000,
  });

Results:
amountToReceive: 0
bridgeFee: 30000000000000000000

Note: bridge Fee is invalid format on Arbritrum. It should be formatted in decimal 6

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module

I got this issue with the synapse protocol version v93. Node version v1.14.18.1

../node_modules/@synapseprotocol/sdk/dist/index.js
require() of ES modules is not supported.

Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from ../node_modules/@synapseprotocol/sdk/package.json.

Bug: Cannot read property 'error' of undefined

Reported by a user on the API chat here: synapsecns/synapse-api#39 (comment)

Here is a gist that results in the SDK call failing:

import {Bridge, Tokens} from "@synapseprotocol/sdk";
import {BigNumber} from "ethers";

const bridge = new Bridge.SynapseBridge({
    network: 56,
});

const estimate = await bridge.estimateBridgeTokenOutput({
    tokenFrom: Tokens.BUSD,
    tokenTo: Tokens.DAI,
    chainIdTo: 137,
    amountFrom: BigNumber.from("10"),
});
const unsignedTxn = await bridge.buildBridgeTokenTransaction({
    tokenFrom: Tokens.BUSD,
    chainIdTo: 137,
    tokenTo: Tokens.DAI,
    amountFrom: BigNumber.from("10"),
    amountTo: estimate.amountToReceive,
    addressTo: 0xb1a7863f407e992a5153a54b5d572e00b9b19104
})

console.log(unsignedTxn)

TypeError: Cannot read property 'error' of undefined
at file:///synapse-api/node_modules/@synapseprotocol/sdk/dist/internal/minirpc.js:188:41
at Array.forEach ()
at file:///synapse-api/node_modules/@synapseprotocol/sdk/dist/internal/minirpc.js:186:45
at processTicksAndRejections (node:internal/process/task_queues:96:5)

@bleaker0x

Unique symbols for tokens

W_ETH(https://github.com/synapsecns/sdk/blob/master/src/tokens.ts#L159), WETH for Fantom(https://github.com/synapsecns/sdk/blob/master/src/tokens.ts#L210), WETH for Moonbeam(https://github.com/synapsecns/sdk/blob/master/src/tokens.ts#L172) have the same symbol WETH. The Wrapped Ether token for Avalanche is WETH_E with no indication it's avalanche other than it's addresses array

More dangeriously, DFK_USDC (https://github.com/synapsecns/sdk/blob/dev/src/tokens.ts#L316)and USDC(https://github.com/synapsecns/sdk/blob/master/src/tokens.ts#L42) have the same symbol!

This tends to create issues with the API and doesn't provide any unique identifier for tokens other than the hash of the BaseToken itself

checkCanBridge is private

I'd like to check if it's possible to bridge token and if it's not then execute approval function.

private async checkCanBridge(args: {

Right now I can only react on exception executing token bridge.
Or I've missed some other workaround?

Generated bridge transaction failing

Hey there :)

I am trying to use the generate_unsigned_bridge_txn endpoint in the synapse-api to build a script which will send JEWEL from DFK Chain to Harmony in Python.

I believe this API uses the buildBridgeTokenTransaction function.

I am working in Python 3.9 with web3py

I am doing the following:

1) I send a request to the generate_unsigned_bridge_txn endpoint

'fromChain': 53935,
'toChain': 1666600000,
'fromToken': 'JEWEL',
'toToken': 'JEWEL',
'amountFrom': '1000000000000000000',
'addressTo': '0x919d17174Fb22CC1Cfc8748C208104EC62341791'

In plaintext, the above would translate to:

Send 1 JEWEL from DFK Chain to Harmony for JEWEL on Harmony.

2) This is the response I get back from the API is the following (I have shorted unsigned_data so I dont make a mess ๐Ÿ™‚):

{
    'unsigned_data': '0xa9fd8c57000000000000000000000000919d17174f...',
    'to': '0x75224b0f245Fe51d5bf47A898DbB6720D4150BA7',
    'chainId': 53935,
    'value': '1'
}

3) So then I create a transaction object:

transaction = {
    'nonce': w3.eth.getTransactionCount(walletAddress),
    "chainId": bridgeTransaction["chainId"],
    'to': bridgeTransaction["to"],
    'gas': 100206,
    'gasPrice': w3.eth.gas_price,
    'data': bridgeTransaction["unsigned_data"]
}

which looks like

{'nonce': 6,
 'chainId': 53935,
 'to': '0x75224b0f245Fe51d5bf47A898DbB6720D4150BA7',
 'gas': 100206,
 'gasPrice': 40000000,
 'data': '0xa9fd8c57000000000000000000000000919d17174f...'} 

4) I then sign it using sign_transaction

signedTransaction = w3.eth.account.sign_transaction(transaction, privateKey)

5) and send the raw transaction using https://web3py.readthedocs.io/en/stable/web3.eth.html?highlight=sign_transaction#web3.eth.Eth.send_raw_transaction

sentTransaction = w3.eth.send_raw_transaction(signedTransaction.rawTransaction)

6) The problem is the transaction get sent but it fails

Heres the failing transaction of the above example: 0xa799782030cdf5c1e5e927f5624ae42e0e3e1cc2ff9ac71013168482d018474b

I am just wondering why my transaction is failing.

One thing I did notice is there is a difference in the content of the data sent in my failed bridge transaction versus a successful bridge transaction

As highlighted with the two green rectangles - it looks like there are two missing chunks in the data. Not sure if this is the cause but wanted to offer some help.

Screenshot 2022-06-02 at 10 31 07

Here is the full data sent by the failed transaction:

0xa9fd8c57000000000000000000000000919d17174fb22cc1cfc8748c208104ec623417910000000000000000000000000000000000000000000000000000000063564c4000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000062974fae

I also noticed that the value of my transaction was 0 JEWEL which is odd as the successful transaction had a value of 108.2 JEWEL

Screenshot 2022-06-02 at 10 43 58

I tried to add this value param to the transaction and it didn't like it ๐Ÿค”

{'nonce': 9,
 'chainId': 53935,
 'to': '0x75224b0f245Fe51d5bf47A898DbB6720D4150BA7',
 'gas': 100206,
 'value': '1000000000000000000',
 'gasPrice': 40000000,
 'data': '0xa9fd8c57000000000000000000000000919d17174fb22cc1cfc8748c208104ec623417910000000000000000000000000000000000000000000000000000000063564c40....'}

TypeError: Transaction had invalid fields: {'value': '1000000000000000000'}

Generated bridge transaction failing

Hey there :)

I am trying to use the generate_unsigned_bridge_txn endpoint in the synapse-api to build a script which will send JEWEL from DFK Chain to Harmony in Python.

I believe this API uses the buildBridgeTokenTransaction function.

I am working in Python 3.9 with web3py

I am doing the following:

1) I send a request to the generate_unsigned_bridge_txn endpoint

'fromChain': 53935,
'toChain': 1666600000,
'fromToken': 'JEWEL',
'toToken': 'JEWEL',
'amountFrom': '1000000000000000000',
'addressTo': '0x919d17174Fb22CC1Cfc8748C208104EC62341791'

In plaintext, the above would translate to:

Send 1 JEWEL from DFK Chain to Harmony for JEWEL on Harmony.

2) This is the response I get back from the API is the following (I have shorted unsigned_data so I dont make a mess ๐Ÿ™‚):

{
    'unsigned_data': '0xa9fd8c57000000000000000000000000919d17174f...',
    'to': '0x75224b0f245Fe51d5bf47A898DbB6720D4150BA7',
    'chainId': 53935,
    'value': '1'
}

3) So then I create a transaction object:

transaction = {
    'nonce': w3.eth.getTransactionCount(walletAddress),
    "chainId": bridgeTransaction["chainId"],
    'to': bridgeTransaction["to"],
    'gas': 100206,
    'gasPrice': w3.eth.gas_price,
    'data': bridgeTransaction["unsigned_data"]
}

which looks like

{'nonce': 6,
 'chainId': 53935,
 'to': '0x75224b0f245Fe51d5bf47A898DbB6720D4150BA7',
 'gas': 100206,
 'gasPrice': 40000000,
 'data': '0xa9fd8c57000000000000000000000000919d17174f...'} 

4) I then sign it using sign_transaction

signedTransaction = w3.eth.account.sign_transaction(transaction, privateKey)

5) and send the raw transaction using https://web3py.readthedocs.io/en/stable/web3.eth.html?highlight=sign_transaction#web3.eth.Eth.send_raw_transaction

sentTransaction = w3.eth.send_raw_transaction(signedTransaction.rawTransaction)

6) The problem is the transaction get sent but it fails

Heres the failing transaction of the above example: 0xa799782030cdf5c1e5e927f5624ae42e0e3e1cc2ff9ac71013168482d018474b

I am just wondering why my transaction is failing.

One thing I did notice is there is a difference in the content of the data sent in my failed bridge transaction versus a successful bridge transaction

As highlighted with the two green rectangles - it looks like there are two missing chunks in the data. Not sure if this is the cause but wanted to offer some help.

Screenshot 2022-06-02 at 10 31 07

Here is the full data sent by the failed transaction:

0xa9fd8c57000000000000000000000000919d17174fb22cc1cfc8748c208104ec623417910000000000000000000000000000000000000000000000000000000063564c4000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000062974fae

I also noticed that the value of my transaction was 0 JEWEL which is odd as the successful transaction had a value of 108.2 JEWEL

Screenshot 2022-06-02 at 10 43 58

I tried to add this value param to the transaction and it didn't like it ๐Ÿค”

{'nonce': 9,
 'chainId': 53935,
 'to': '0x75224b0f245Fe51d5bf47A898DbB6720D4150BA7',
 'gas': 100206,
 'value': '1000000000000000000',
 'gasPrice': 40000000,
 'data': '0xa9fd8c57000000000000000000000000919d17174fb22cc1cfc8748c208104ec623417910000000000000000000000000000000000000000000000000000000063564c40....'}

TypeError: Transaction had invalid fields: {'value': '1000000000000000000'}

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • Lock file maintenance

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update dev dependencies (minor/patch/pin) (@typechain/ethers-v5, @types/chai-as-promised, @types/chai-things, @types/lodash, @types/lodash-es, @types/node, @types/react, c8, chai, mocha, ts-node, ts-patch, typechain, typedoc, typescript, typescript-transform-paths)

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

npm
package.json
  • @ethersproject/abi ^5.5.0
  • @ethersproject/abstract-signer ^5.5.0
  • @ethersproject/bignumber ^5.5.0
  • @ethersproject/bytes ^5.5.0
  • @ethersproject/constants ^5.5.0
  • @ethersproject/contracts ^5.5.0
  • @ethersproject/providers ^5.5.0
  • @ethersproject/transactions ^5.5.0
  • @ethersproject/units ^5.5.0
  • @ethersproject/wallet ^5.5.0
  • @ethersproject/web ^5.5.1
  • ethers ^5.5.1
  • lodash ^4.17.21
  • lodash-es ^4.17.21
  • node-fetch ^3.2.6
  • object-hash ^3.0.0
  • @ethereum-waffle/chai 3.4.4
  • @typechain/ethers-v5 10.1.0
  • @types/chai-as-promised 7.1.5
  • @types/chai-things 0.0.35
  • @types/lodash 4.14.185
  • @types/lodash-es 4.17.6
  • @types/mocha 9.1.1
  • @types/node 17.0.21
  • @types/object-hash 2.2.1
  • @types/react 18.0.21
  • @zoltu/typescript-transformer-append-js-extension 1.0.1
  • c8 7.12.0
  • chai 4.3.6
  • chai-as-promised 7.1.1
  • chai-things 0.2.0
  • coveralls 3.1.1
  • dotenv 16.0.0
  • mocha 10.0.0
  • mocha-lcov-reporter 1.3.0
  • mocha-steps 1.3.0
  • ts-mocha 10.0.0
  • ts-node 10.9.1
  • ts-patch 2.0.2
  • typechain 8.1.0
  • typedoc ^0.23.21
  • typescript 4.7.4
  • typescript-transform-paths 3.3.1

  • Check this box to trigger a request for Renovate to run again on this repository

support for coingecko ids

Need to be able to pull some coin data from coingecko. Was thinking we could integrate coingecko IDs in the the SDK token objects themselves as an attribute ? @bleaker0x

HIGH = 'highstreet'
SYN = 'synapse-2'
USDT = 'tether'
USDC = 'usd-coin'
BUSD = 'binance-usd'
DAI = 'dai'
ETH = 'ethereum'
DOG = 'the-doge-nft'
NRV = 'nerve-finance'
MIM = 'magic-internet-money'
FRAX = 'frax'
BNB = 'binancecoin'
AVAX = 'avalanche-2'
ONE = 'harmony'
MATIC = 'matic-network'
FTM = 'fantom'
MOVR = 'moonriver'
NFD = 'feisty-doge-nft'
JUMP = 'hyperjump'
OHM = 'olympus'
WSOHM = 'wrapped-staked-olympus'
JGN = 'juggernaut'
GOHM = 'governance-ohm'
SOLAR = 'solarbeam'
GMX = 'gmx'
GLMR = 'moonbeam'
CRO = 'crypto-com-chain'
METIS = 'metis-token'
NEWO = 'new-order'
SDT = 'stake-dao'
LUNA = 'terra-luna'
JEWEL = 'defi-kingdoms'
XJEWEL = 'xjewel'
UST = 'terrausd'
VSTA = 'vesta-finance'
SFI = 'saffron-finance'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.