Skip to content

Commit

Permalink
Merge branch 'main' into fs-954-add-prepareRegisterNewNetworkParams
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx authored Oct 31, 2024
2 parents f9222a9 + be6a3d7 commit 6965d7f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ import {
createRollupGetRetryablesFees,
createRollupGetRetryablesFeesWithDefaults,
} from './createRollupGetRetryablesFees';
import {
fetchAllowance,
FetchAllowanceProps,
fetchDecimals,
FetchDecimalsProps,
} from './utils/erc20';

export {
arbOwnerPublicActions,
Expand Down Expand Up @@ -290,4 +296,9 @@ export {
CreateRollupGetRetryablesFeesParams,
//
createTokenBridgeDefaultRetryablesFees,
//
fetchAllowance,
FetchAllowanceProps,
fetchDecimals,
FetchDecimalsProps,
};
4 changes: 2 additions & 2 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@arbitrum/orbit-sdk",
"description": "TypeScript SDK for building Arbitrum Orbit chains",
"version": "0.21.2-beta.1",
"version": "0.21.2-beta.2",
"main": "./dist/index.js",
"files": [
"./dist"
Expand Down Expand Up @@ -51,7 +51,7 @@
"viem": "^1.20.0"
},
"dependencies": {
"@arbitrum/sdk": "^4.0.2-beta.0",
"@arbitrum/sdk": "^4.0.2-beta.1",
"@arbitrum/token-bridge-contracts": "^1.2.2",
"@offchainlabs/fund-distribution-contracts": "^1.0.1",
"@safe-global/protocol-kit": "^4.0.2",
Expand Down
16 changes: 11 additions & 5 deletions src/utils/decimals.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BigNumber } from 'ethers';
import {
scaleToNativeTokenDecimals as ethers_scaleToNativeTokenDecimals,
nativeTokenDecimalsTo18Decimals as ethers_nativeTokenDecimalsTo18Decimals,
} from '@arbitrum/sdk/dist/lib/utils/lib';
scaleFrom18DecimalsToNativeTokenDecimals as ethers_scaleFrom18DecimalsToNativeTokenDecimals,
scaleFromNativeTokenDecimalsTo18Decimals as ethers_scaleFromNativeTokenDecimalsTo18Decimals,
} from '@arbitrum/sdk';

/**
* Scales a value from 18 decimals to the number of decimals of the native token.
Expand All @@ -20,7 +20,10 @@ export function scaleFrom18DecimalsToNativeTokenDecimals({
decimals: number;
}): bigint {
const amountBigNumber = BigNumber.from(amount);
const result = ethers_scaleToNativeTokenDecimals({ amount: amountBigNumber, decimals });
const result = ethers_scaleFrom18DecimalsToNativeTokenDecimals({
amount: amountBigNumber,
decimals,
});
return BigInt(result.toString());
}

Expand All @@ -40,6 +43,9 @@ export function scaleFromNativeTokenDecimalsTo18Decimals({
decimals: number;
}): bigint {
const amountBigNumber = BigNumber.from(amount);
const result = ethers_nativeTokenDecimalsTo18Decimals({ amount: amountBigNumber, decimals });
const result = ethers_scaleFromNativeTokenDecimalsTo18Decimals({
amount: amountBigNumber,
decimals,
});
return BigInt(result.toString());
}
10 changes: 6 additions & 4 deletions src/utils/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ export async function fetchAllowance<TChain extends Chain | undefined>({
});
}

export type FetchDecimalsProps<TChain extends Chain | undefined> = {
address: Address;
publicClient: PublicClient<Transport, TChain>;
};

export function fetchDecimals<TChain extends Chain | undefined>({
address,
publicClient,
}: {
address: Address;
publicClient: PublicClient<Transport, TChain>;
}) {
}: FetchDecimalsProps<TChain>) {
return publicClient.readContract({
address,
abi: erc20ABI,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"@openzeppelin/contracts-upgradeable" "4.5.2"
patch-package "^6.4.7"

"@arbitrum/sdk@^4.0.2-beta.0":
version "4.0.2-beta.0"
resolved "https://registry.yarnpkg.com/@arbitrum/sdk/-/sdk-4.0.2-beta.0.tgz#864e38797d9f25e0b0d6a5f0147d60bd5b5db3b6"
integrity sha512-Q22DqEYzlkspvx6h9LUgTFgpUr9PNtPiyp4hTaODOdNl+cbpVAz6G9x04iMAnNia9sP0KffhDD5WxS4CzFrFFw==
"@arbitrum/sdk@^4.0.2-beta.1":
version "4.0.2-beta.1"
resolved "https://registry.yarnpkg.com/@arbitrum/sdk/-/sdk-4.0.2-beta.1.tgz#c6c6c5784a8eaa6a4edab3600f765e9f82ce5988"
integrity sha512-a5DG6+Ld3X4L8H3CTUl3gc27Bj/Pqjo+5UZiCI97SM2mHtHKWF1BgQ+FCk/8bgFUP5nS9dXBl5tPJRtCFfOe0A==
dependencies:
"@ethersproject/address" "^5.0.8"
"@ethersproject/bignumber" "^5.1.1"
Expand Down

0 comments on commit 6965d7f

Please sign in to comment.