-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from celo-org/feat/cip64
feat: cip64 and eip1559
- Loading branch information
Showing
8 changed files
with
1,156 additions
and
927 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const Y_PARITY_EIP_2098 = 27; | ||
export const EIP155_NUMBER = 35; | ||
// NOTE: Black magic number, unsure where it comes from | ||
export const EIGHT = 8; | ||
|
||
// NOTE: Logic stolen from https://github.com/celo-org/celo-monorepo/blob/e7ebc92cb0715dc56c9d7f613dca81e076541cf3/packages/sdk/connect/src/connection.ts#L382-L396 | ||
export const GAS_INFLATION_FACTOR = 1.3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { BigNumber, BigNumberish } from "ethers"; | ||
import { hexlify } from "ethers/lib/utils"; | ||
import { GAS_INFLATION_FACTOR } from "../../consts"; | ||
|
||
function isEmpty(value: string | BigNumberish | undefined | null) { | ||
return ( | ||
value === undefined || | ||
value === null || | ||
value === "0" || | ||
(typeof value == "string" | ||
? value.toLowerCase() === "0x" || value.toLowerCase() === "0x0" | ||
: hexlify(value) === "0x0") | ||
); | ||
} | ||
|
||
function isPresent(value: string | BigNumberish | undefined | null) { | ||
return !isEmpty(value); | ||
} | ||
|
||
export function isEIP1559(tx: any): boolean { | ||
return isPresent(tx.maxFeePerGas) && isPresent(tx.maxPriorityFeePerGas); | ||
} | ||
|
||
export function isCIP64(tx: any) { | ||
return ( | ||
isEIP1559(tx) && | ||
isPresent(tx.feeCurrency) && | ||
!isPresent(tx.gatewayFeeRecipient) && | ||
!isPresent(tx.gatewayFeeRecipient) | ||
); | ||
} | ||
|
||
export function isCIP42(tx: any): boolean { | ||
return ( | ||
isEIP1559(tx) && | ||
(isPresent(tx.feeCurrency) || | ||
isPresent(tx.gatewayFeeRecipient) || | ||
isPresent(tx.gatewayFee)) | ||
); | ||
} | ||
|
||
export function concatHex(values: string[]): `0x${string}` { | ||
return `0x${values.reduce((acc, x) => acc + x.replace("0x", ""), "")}`; | ||
} | ||
|
||
export function omit<T extends Object, K extends (keyof T)[]>( | ||
object: T, | ||
...keys: K | ||
): { | ||
[Key in keyof T as Key extends K ? never : Key]: T[Key]; | ||
} { | ||
return Object.keys(object) | ||
.filter((key) => !keys.includes(key as keyof T)) | ||
.reduce((acc, key) => { | ||
acc[key as keyof T] = object[key as keyof T]; | ||
return acc; | ||
}, {} as T); | ||
} | ||
|
||
export function adjustForGasInflation(gas: BigNumber): BigNumber { | ||
// NOTE: prevent floating point math | ||
return gas.mul(Math.floor(GAS_INFLATION_FACTOR * 100)).div(100); | ||
} |
Oops, something went wrong.