Giter VIP home page Giter VIP logo

arbitrum-sdk's People

Stargazers

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

Watchers

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

arbitrum-sdk's Issues

arbitrum-sdk not supported `local` dev enviroment.

I startup a local enviroment on ubuntu, which the l1ChainId is 412346.

and deposit Eth by arbitrum-tutorial, and it returns the following error:

root@iZj6cf3sxrlbuuiwe8tsonZ:~/arbitrum-tutorials/packages/eth-deposit# yarn run depositETH
yarn run v1.22.19
$ hardhat run scripts/exec.js
Environmental variables properly set ๐Ÿ‘
                            ๐Ÿ”ต๐Ÿ”ต                            
                           ๐Ÿ”ต  ๐Ÿ”ต                           
                          ๐Ÿ”ต    ๐Ÿ”ต                          
                         ๐Ÿ”ต      ๐Ÿ”ต                         
                        ๐Ÿ”ต        ๐Ÿ”ต                        
                       ๐Ÿ”ต          ๐Ÿ”ต                       
                      ๐Ÿ”ต            ๐Ÿ”ต                      
                     ๐Ÿ”ต              ๐Ÿ”ต                     
                    ๐Ÿ”ต                ๐Ÿ”ต                    
                   ๐Ÿ”ต                  ๐Ÿ”ต                   
                  ๐Ÿ”ต                    ๐Ÿ”ต                  
                 ๐Ÿ”ต                      ๐Ÿ”ต                 
                ๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต                
               ๐Ÿ”ต                          ๐Ÿ”ต               
              ๐Ÿ”ต                            ๐Ÿ”ต              
             ๐Ÿ”ต                              ๐Ÿ”ต             
            ๐Ÿ”ต                                ๐Ÿ”ต            
           ๐Ÿ”ต                                  ๐Ÿ”ต           
          ๐Ÿ”ต                                    ๐Ÿ”ต          
         ๐Ÿ”ต                                      ๐Ÿ”ต         
        ๐Ÿ”ต                                        ๐Ÿ”ต        
       ๐Ÿ”ต                                          ๐Ÿ”ต       
      ๐Ÿ”ต                                            ๐Ÿ”ต      
     ๐Ÿ”ต                                              ๐Ÿ”ต     
    ๐Ÿ”ต                                                ๐Ÿ”ต    
Arbitrum Demo: Deposit Eth via Arbitrum SDK
Lets
Go โžก๏ธ
...๐Ÿš€

ArbSdkError: Unrecognized network 412346.
    at getNetwork (/root/arbitrum-tutorials/node_modules/@arbitrum/sdk-nitro/dist/lib/dataEntities/networks.js:223:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at isNitroL2 (/root/arbitrum-tutorials/node_modules/@arbitrum/sdk/dist/lib/utils/migration_types.js:192:23)
    at getL2Network (/root/arbitrum-tutorials/node_modules/@arbitrum/sdk/dist/lib/dataEntities/networks.js:64:9)
    at main (/root/arbitrum-tutorials/packages/eth-deposit/scripts/exec.js:36:21) {
  inner: undefined
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Enable overriding the initially set L1 Provider on `L2ToL1Message`

To perform a withdrawal claim transaction, the following two lines are used to obtain the transaction hash:

const messageWriter = L2ToL1Message.fromEvent(l1Signer, event)
const res = await messageWriter.execute(l2.provider)
// res.hash will be the transaction hash used for tx submission later on

With l1Signer, L2ToL1MessageWriter is created.

public static fromEvent<T extends SignerOrProvider>(
l1SignerOrProvider: T,
event: L2ToL1TransactionEvent
): L2ToL1MessageReaderOrWriter<T>
static fromEvent<T extends SignerOrProvider>(
l1SignerOrProvider: T,
event: L2ToL1TransactionEvent
): L2ToL1MessageReader | L2ToL1MessageWriter {
return SignerProviderUtils.isSigner(l1SignerOrProvider)
? new L2ToL1MessageWriter(l1SignerOrProvider, event)
: new L2ToL1MessageReader(l1SignerOrProvider, event)
}

export class L2ToL1MessageWriter extends L2ToL1MessageReader {
private readonly classicWriter?: classic.L2ToL1MessageWriterClassic
private readonly nitroWriter?: nitro.L2ToL1MessageWriterNitro
constructor(l1Signer: Signer, event: L2ToL1TransactionEvent) {
super(l1Signer.provider!, event)
if (this.isClassic(event)) {
this.classicWriter = new classic.L2ToL1MessageWriterClassic(
l1Signer,
event.batchNumber,
event.indexInBatch
)
} else {
this.nitroWriter = new nitro.L2ToL1MessageWriterNitro(l1Signer, event)
}
}

Since L2ToL1MessageWriter extends L2ToL1MessageReader, let's look at L2ToL1MessageReader.
Here, we can see that l1Signer.provider is assigned to l1Provider in the class in the constructor.

export class L2ToL1MessageReader extends L2ToL1Message {
private readonly classicReader?: classic.L2ToL1MessageReaderClassic
private readonly nitroReader?: nitro.L2ToL1MessageReaderNitro
constructor(
protected readonly l1Provider: Provider,
event: L2ToL1TransactionEvent
) {

The issue we encountered concerned only L2ToL1MessageWriterNitro and now we are in the nitro era, so let's look at L2ToL1MessageWriterNitro.
It calls a method getOutboxProof using the l2Provider passed in, which seems to cover all we need.

public async execute(
l2Provider: Provider,
overrides?: Overrides
): Promise<ContractTransaction> {
const status = await this.status(l2Provider)
if (status !== L2ToL1MessageStatus.CONFIRMED) {
throw new ArbSdkError(
`Cannot execute message. Status is: ${status} but must be ${L2ToL1MessageStatus.CONFIRMED}.`
)
}
const proof = await this.getOutboxProof(l2Provider)

In getOutboxProof, it calls getSendProps with the l2Provider.

public async getOutboxProof(l2Provider: Provider) {
const { sendRootSize } = await this.getSendProps(l2Provider)

Here we can see this.l1Provider which is the provider from the l1Signer object used.
If the provider is missing some essential properties for the node to call the contract method statically, our transaction would fail, which was what we experienced.

protected async getSendProps(l2Provider: Provider) {
if (!this.sendRootConfirmed) {
const l2Network = await getL2Network(l2Provider)
const rollup = RollupUserLogic__factory.connect(
l2Network.ethBridge.rollup,
this.l1Provider
)
const latestConfirmedNodeNum = await rollup.callStatic.latestConfirmed()

I got an error calling yarn gen:network

yarn run v1.22.19
$ ts-node ./scripts/genNetwork.ts
123
Error: call revert exception [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="confirmPeriodBlocks()", data="0x", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.6.3)
    at Logger.makeError (/home/test/arbitrum-tutorials/arbitrum-sdk/node_modules/@ethersproject/logger/src.ts/index.ts:261:28)
    at Logger.throwError (/home/test/arbitrum-tutorials/arbitrum-sdk/node_modules/@ethersproject/logger/src.ts/index.ts:273:20)
    at Interface.decodeFunctionResult (/home/test/arbitrum-tutorials/arbitrum-sdk/node_modules/@ethersproject/abi/src.ts/interface.ts:427:23)
    at Contract.<anonymous> (/home/test/arbitrum-tutorials/arbitrum-sdk/node_modules/@ethersproject/contracts/src.ts/index.ts:400:44)
    at step (/home/test/arbitrum-tutorials/arbitrum-sdk/node_modules/@ethersproject/contracts/lib/index.js:48:23)
    at Object.next (/home/test/arbitrum-tutorials/arbitrum-sdk/node_modules/@ethersproject/contracts/lib/index.js:29:53)
    at fulfilled (/home/test/arbitrum-tutorials/arbitrum-sdk/node_modules/@ethersproject/contracts/lib/index.js:20:58)
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  reason: null,
  code: 'CALL_EXCEPTION',
  method: 'confirmPeriodBlocks()',
  data: '0x',
  errorArgs: null,
  errorName: null,
  errorSignature: null,
  address: '0x91c9ca402976984c99ebd2b43826123442c592b8',
  args: [],
  transaction: {
    data: '0x2e7acfa6',
    to: '0x91c9Ca402976984C99eBD2B43826123442c592B8'
  }
}
Done in 23.25s.

yarn gen:network not worked smootly for `ubuntu`

On my ubuntu machine, I startup a local enviroment.
I used yarn gen:network to generate localNetwork.json, whick reported:

Error: No such container: nitro_sequencer_1
Error: Command failed: docker exec nitro_sequencer_1 cat /config/deployment.json
Error: No such container: nitro_sequencer_1

    at checkExecSyncError (node:child_process:841:11)
    at execSync (node:child_process:912:15)
    at getCustomNetworks (/root/arbitrum-sdk/scripts/testSetup.ts:65:34)
    at setupNetworks (/root/arbitrum-sdk/scripts/testSetup.ts:131:74)
    at main (/root/arbitrum-sdk/scripts/genNetwork.ts:12:55)
    at Object.<anonymous> (/root/arbitrum-sdk/scripts/genNetwork.ts:26:1)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Module.m._compile (/root/arbitrum-sdk/node_modules/ts-node/src/index.ts:1597:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1180:10) {
  status: 1,
  signal: null,
  output: [
    null,
    <Buffer >,
    <Buffer 45 72 72 6f 72 3a 20 4e 6f 20 73 75 63 68 20 63 6f 6e 74 61 69 6e 65 72 3a 20 6e 69 74 72 6f 5f 73 65 71 75 65 6e 63 65 72 5f 31 0a>
  ],
  pid: 41792,
  stdout: <Buffer >,
  stderr: <Buffer 45 72 72 6f 72 3a 20 4e 6f 20 73 75 63 68 20 63 6f 6e 74 61 69 6e 65 72 3a 20 6e 69 74 72 6f 5f 73 65 71 75 65 6e 63 65 72 5f 31 0a>
}
Done in 10.15s.

It looks like the nitro_sequencer_1 is called nitro-sequencer-1 on ubuntu.

v4

Changes should land into the v4 branch. The branch should be kept in sync with main.

Tasks

  1. 11 of 11

Support `viem` in addition to `ethers`

gas-estimation for smart contract not working

Hello
Im trying to estimate gas for transaction using

https://github.com/OffchainLabs/arbitrum-tutorials/tree/master/packages/gas-estimation

It works fine when I estimate simple transaction like sending ETH between 2 addresses without any additional data.
But when I pass the smart contract data like this:
0x1114cd2a000000000000000000000000000000000000000000000000000000000000006f000000000000000000000000409d44c6998bbdaa982f14b1cf2f12958b70abd800000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000003b9ac9ff000000000000000000000000000000000000000000000000000000003b02337f0000000000000000000000000000000000000000000000000000000000000014409d44c6998bbdaa982f14b1cf2f12958b70abd8000000000000000000000000

Script always return an error.

Error: call revert exception; VM Exception while processing transaction: reverted with reason string "Stargate: msg.value must be > _amountLD" [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (method="gasEstimateComponents(address,bool,bytes)", data="0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002753746172676174653a206d73672e76616c7565206d757374206265203e205f616d6f756e744c4400000000000000000000000000000000000000000000000000", errorArgs=["Stargate: msg.value must be > _amountLD"], errorName="Error", errorSignature="Error(string)", reason="Stargate: msg.value must be > _amountLD", code=CALL_EXCEPTION, version=abi/5.7.0)
at Logger.makeError (C:\Users\97158\Documents\GitHub\layerZero\node_modules@ethersproject\logger\src.ts\index.ts:269:28)
at Logger.throwError (C:\Users\97158\Documents\GitHub\layerZero\node_modules@ethersproject\logger\src.ts\index.ts:281:20)
errorSignature: 'Error(string)',
address: '0x00000000000000000000000000000000000000C8',
args: [
'0xbf22f0f184bccbea268df387a49ff5238dd23e40',
false,
'0x1114cd2a000000000000000000000000000000000000000000000000000000000000006f000000000000000000000000409d44c6998bbdaa982f14b1cf2f12958b70abd800000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000003b9ac9ff000000000000000000000000000000000000000000000000000000003b02337f0000000000000000000000000000000000000000000000000000000000000014409d44c6998bbdaa982f14b1cf2f12958b70abd8000000000000000000000000'
],
transaction: {
data: '0xc94e6eeb000000000000000000000000bf22f0f184bccbea268df387a49ff5238dd23e400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e41114cd2a000000000000000000000000000000000000000000000000000000000000006f000000000000000000000000409d44c6998bbdaa982f14b1cf2f12958b70abd800000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000003b9ac9ff000000000000000000000000000000000000000000000000000000003b02337f0000000000000000000000000000000000000000000000000000000000000014409d44c6998bbdaa982f14b1cf2f12958b70abd800000000000000000000000000000000000000000000000000000000000000000000000000000000',
to: '0x00000000000000000000000000000000000000C8'

And this error looks like nodeInterface.callStatic.gasEstimateComponents trying to execute transaction instead of estimate it.

transaction details.
0xbf22f0f184bccbea268df387a49ff5238dd23e40 - smart contract
swapETH - method

contract.methods
      .swapETH(
        destinationChainId, //111
        request.senderAccount.address, //my address
        request.senderAccount.address, //my address
        request.amount, //0.04 eth (in wei)
        minAmount  //0.04 eth * 0.99 (in wei)
      )
      .encodeABI();

const baseL2Provider = new providers.StaticJsonRpcProvider(
      "https://arb1.arbitrum.io/rpc"
    );

    addDefaultLocalNetwork();

    const destinationAddress =contractAddress;
    const nodeInterface = NodeInterface__factory.connect(
      NODE_INTERFACE_ADDRESS,
      baseL2Provider
    );

//THROWING HERE
    const gasEstimateComponents =
      await nodeInterface.callStatic.gasEstimateComponents(
        destinationAddress,
        false,
        data,
        {
          blockTag: "latest",
        }
      );

    const l1GasEstimated = gasEstimateComponents.gasEstimateForL1;
    const l2GasUsed = gasEstimateComponents.gasEstimate.sub(
      gasEstimateComponents.gasEstimateForL1
    );
    const l2EstimatedPrice = gasEstimateComponents.baseFee;
    const l1EstimatedPrice = gasEstimateComponents.l1BaseFeeEstimate.mul(16);

    const l1Cost = l1GasEstimated.mul(l2EstimatedPrice);
    const l1Size = l1Cost.div(l1EstimatedPrice);

    const P = l2EstimatedPrice;
    const L2G = l2GasUsed;
    const L1P = l1EstimatedPrice;
    const L1S = l1Size;

    // L1C (L1 Cost) = L1P * L1S
    const L1C = L1P.mul(L1S);

    // B (Extra Buffer) = L1C / P
    const B = L1C.div(P);

    // G (Gas Limit) = L2G + B
    const G = L2G.add(B);

    // TXFEES (Transaction fees) = P * G
    const TXFEES = P.mul(G);

    return {
      fullGas: G.toNumber(),
      transactionFee: TXFEES.toNumber(),
    };

Deploying ArbSys and ArbRetryableTx using ganache

Is there a way to deploy ArbSys and ArbRetryableTx at the same addresses that are used in production while using Ganache?

ArbSys address: 0x0000000000000000000000000000000000000064
ArbRetryableTx address: 0x000000000000000000000000000000000000006E

More generally, if you can point to some test or deployment script in this repo or the Arbitrum monorepo, that would be helpful.

Nitro network is not generated when using L2ToL1Message directly

In most flow, we call isNitroL1 or isNitroL2 in the migration sdk to detect if the network is nitro, if so we call generateL2NitroNetwork to update the contract addresses from the delayed inbox.

const nitroL2Network = await generateL2NitroNetwork(
l2Network,
SignerProviderUtils.getProviderOrThrow(l1Provider)
)

However in L2ToL1Message constructor we never call isNitroL1 or isNitroL2 and hence the network is not generated

} else {
this.nitroReader = new nitro.L2ToL1MessageReader(l1Provider, event)
}

Update L1/L2 language throughout the codebase

Enable getting getL2Network via an rpc url

A general pattern I think all rollups should land on as we move to a multi rollup world is the ability to get the rollup config on chain. This way you can bootstrap the arbitrum sdk with only the rpc url even if the rollup config hasn't been added to this sdk yet.

e.g.

const l2Network = await getL2NetworkFromRpc(
  l2RpcUrl /** <-- rpc url of target Arbitrum chain */
)

This allows us to more easily make tooling work for all chains without needing to specify the config within the library first or needing to tediously craft your own config

Separate unit and integration tests

These are currently run as part of the same job, but this integration tests are slow and require eternal deps, unit tests do not. We should separate them so it's easy to quickly run unit tests

Unrecognized network 421612

calling estimateAll on an instance of L1ToL2MessageGasEstimator throws an error ArbSdkError: Unrecognized network 421612.
Looked into the source files to notice that the network config for nitro is missing.

Is there an easy workaround for this?
tried package v2.0.0 and v3.0.0-beta2

Explore ways to support multiple client libraries

Currently, in order to use the Arbitrum SDK in your project, you have to use ethers@v5, as a lot (if not all) SDK methods accept and receive ethers@v5 objects, like Signer, Provider, TransactionReceipt etc.

Ideally, we should be able to support using any of them, e.g. ethers@v5, ethers@v6, viem, web3.js etc, while continuing to use ethers for our implementation. Maybe we could reduce the dependencies to the minimum interfaces needed, and then write small adapters that map objects from different libraries to the shared interfaces? It would be cool if the user could just "pick" an adapter once when configuring the library without having to do it at every call site.

As a PoC, we could try doing so for a couple of read and write methods:

This is a huge breaking change so probably targets v4, but worth exploring.

The parameter description for bridgeStandardToken is wrong

In your Readme file you mentioned that for bridgeStandardToken command:

Required CL params: networkID:number โ€” Chain ID of L1 network l1TokenAddress:string โ€” address of L1 token to be bridged

But actually, the networkID should be L2 network id.

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.