Skip to content

Commit

Permalink
update names and add jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc committed Oct 29, 2024
1 parent 55bb2eb commit 285d043
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/createRollupEnoughCustomFeeTokenAllowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getRollupCreatorAddress } from './utils/getRollupCreatorAddress';
import { Prettify } from './types/utils';
import { WithRollupCreatorAddressOverride } from './types/createRollupTypes';
import { createRollupGetRetryablesFeesWithDefaults } from './createRollupGetRetryablesFees';
import { scaleToNativeTokenDecimals } from './utils/decimals';
import { scaleFrom18DecimalsToNativeTokenDecimals } from './utils/decimals';

export type CreateRollupEnoughCustomFeeTokenAllowanceParams<TChain extends Chain | undefined> =
Prettify<
Expand Down Expand Up @@ -43,5 +43,5 @@ export async function createRollupEnoughCustomFeeTokenAllowance<TChain extends C
publicClient,
});

return allowance >= scaleToNativeTokenDecimals({ amount: fees, decimals });
return allowance >= scaleFrom18DecimalsToNativeTokenDecimals({ amount: fees, decimals });
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getRollupCreatorAddress } from './utils/getRollupCreatorAddress';
import { Prettify } from './types/utils';
import { WithRollupCreatorAddressOverride } from './types/createRollupTypes';
import { createRollupGetRetryablesFeesWithDefaults } from './createRollupGetRetryablesFees';
import { scaleToNativeTokenDecimals } from './utils/decimals';
import { scaleFrom18DecimalsToNativeTokenDecimals } from './utils/decimals';

export type CreateRollupPrepareCustomFeeTokenApprovalTransactionRequestParams<
TChain extends Chain | undefined,
Expand Down Expand Up @@ -48,7 +48,7 @@ export async function createRollupPrepareCustomFeeTokenApprovalTransactionReques
address: nativeToken,
owner: account,
spender: rollupCreatorAddressOverride ?? getRollupCreatorAddress(publicClient),
amount: amount ?? scaleToNativeTokenDecimals({ amount: fees, decimals }),
amount: amount ?? scaleFrom18DecimalsToNativeTokenDecimals({ amount: fees, decimals }),
publicClient,
});

Expand Down
6 changes: 3 additions & 3 deletions src/createTokenBridge.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { createTokenBridgePrepareSetWethGatewayTransactionRequest } from './crea
import { createTokenBridgePrepareSetWethGatewayTransactionReceipt } from './createTokenBridgePrepareSetWethGatewayTransactionReceipt';
import { createTokenBridge } from './createTokenBridge';
import { TokenBridgeContracts } from './types/TokenBridgeContracts';
import { scaleToNativeTokenDecimals } from './utils/decimals';
import { scaleFrom18DecimalsToNativeTokenDecimals } from './utils/decimals';

const testnodeAccounts = getNitroTestnodePrivateKeyAccounts();
const l2RollupOwner = testnodeAccounts.l2RollupOwner;
Expand Down Expand Up @@ -223,7 +223,7 @@ describe('createTokenBridge utils function', () => {
functionName: 'transfer',
args: [
l3RollupOwner.address,
scaleToNativeTokenDecimals({ amount: 500n, decimals: nativeTokenDecimals }),
scaleFrom18DecimalsToNativeTokenDecimals({ amount: 500n, decimals: nativeTokenDecimals }),
],
}),
value: BigInt(0),
Expand Down Expand Up @@ -392,7 +392,7 @@ describe('createTokenBridge', () => {
functionName: 'transfer',
args: [
l3RollupOwner.address,
scaleToNativeTokenDecimals({ amount: 500n, decimals: nativeTokenDecimals }),
scaleFrom18DecimalsToNativeTokenDecimals({ amount: 500n, decimals: nativeTokenDecimals }),
],
}),
value: BigInt(0),
Expand Down
4 changes: 2 additions & 2 deletions src/createTokenBridgeEnoughCustomFeeTokenAllowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createTokenBridgeDefaultRetryablesFees } from './constants';
import { Prettify } from './types/utils';
import { WithTokenBridgeCreatorAddressOverride } from './types/createTokenBridgeTypes';
import { getTokenBridgeCreatorAddress } from './utils/getTokenBridgeCreatorAddress';
import { scaleToNativeTokenDecimals } from './utils/decimals';
import { scaleFrom18DecimalsToNativeTokenDecimals } from './utils/decimals';

export type CreateTokenBridgeEnoughCustomFeeTokenAllowanceParams<TChain extends Chain | undefined> =
Prettify<
Expand Down Expand Up @@ -39,7 +39,7 @@ export async function createTokenBridgeEnoughCustomFeeTokenAllowance<

return (
allowance >=
scaleToNativeTokenDecimals({
scaleFrom18DecimalsToNativeTokenDecimals({
amount: createTokenBridgeDefaultRetryablesFees,
decimals,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { validateParentChain } from './types/ParentChain';
import { WithTokenBridgeCreatorAddressOverride } from './types/createTokenBridgeTypes';
import { getTokenBridgeCreatorAddress } from './utils/getTokenBridgeCreatorAddress';
import { createTokenBridgeDefaultRetryablesFees } from './constants';
import { scaleToNativeTokenDecimals } from './utils/decimals';
import { scaleFrom18DecimalsToNativeTokenDecimals } from './utils/decimals';

export type CreateTokenBridgePrepareCustomFeeTokenApprovalTransactionRequestParams<
TChain extends Chain | undefined,
Expand Down Expand Up @@ -42,7 +42,7 @@ export async function createTokenBridgePrepareCustomFeeTokenApprovalTransactionR
spender: tokenBridgeCreatorAddressOverride ?? getTokenBridgeCreatorAddress(publicClient),
amount:
amount ??
scaleToNativeTokenDecimals({
scaleFrom18DecimalsToNativeTokenDecimals({
amount: createTokenBridgeDefaultRetryablesFees,
decimals,
}),
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ import {
} from './wasmModuleRoot';
import { registerCustomParentChain } from './chains';
export * from './actions';
import {
scaleFrom18DecimalsToNativeTokenDecimals,
scaleFromNativeTokenDecimalsTo18Decimals,
} from './utils/decimals';

export {
arbOwnerPublicActions,
Expand Down Expand Up @@ -267,4 +271,7 @@ export {
GetConsensusReleaseByWasmModuleRoot,
//
registerCustomParentChain,
//
scaleFrom18DecimalsToNativeTokenDecimals,
scaleFromNativeTokenDecimalsTo18Decimals,
};
24 changes: 20 additions & 4 deletions src/utils/decimals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,41 @@ import {
nativeTokenDecimalsTo18Decimals as ethers_nativeTokenDecimalsTo18Decimals,
} from '@arbitrum/sdk/dist/lib/utils/lib';

export function scaleToNativeTokenDecimals({
/**
* Scales a value from 18 decimals to the number of decimals of the native token.
*
* @param param.amount The value to scale.
* @param param.decimals The number of decimals of the native token.
*
* @returns The scaled value.
*/
export function scaleFrom18DecimalsToNativeTokenDecimals({
amount,
decimals,
}: {
amount: bigint;
decimals: number;
}) {
}): bigint {
const amountBigNumber = BigNumber.from(amount);
const result = ethers_scaleToNativeTokenDecimals({ amount: amountBigNumber, decimals });
return BigInt(result.toString());
}

export function nativeTokenDecimalsTo18Decimals({
/**
* Scales a value from the number of decimals of the native token to 18 decimals.
*
* @param param.amount The value to scale.
* @param param.decimals The number of decimals of the native token.
*
* @returns The scaled value.
*/
export function scaleFromNativeTokenDecimalsTo18Decimals({
amount,
decimals,
}: {
amount: bigint;
decimals: number;
}) {
}): bigint {
const amountBigNumber = BigNumber.from(amount);
const result = ethers_nativeTokenDecimalsTo18Decimals({ amount: amountBigNumber, decimals });
return BigInt(result.toString());
Expand Down

0 comments on commit 285d043

Please sign in to comment.