-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate makeAddress and use
0x${string}
- Loading branch information
1 parent
eeb6c24
commit 6968c41
Showing
9 changed files
with
20 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,16 @@ | ||
import { BigNumber } from "@ethersproject/bignumber"; | ||
import { TokenBalance } from "./TokenBalance"; | ||
import { TokenKey } from "./tokens"; | ||
|
||
export type AddressContext = Readonly<{ | ||
address: string; | ||
address: `0x${string}`; | ||
tokenBalances: { [tk: TokenKey]: TokenBalance } | ||
}> | ||
|
||
// emptyAddressContext is a convenience and safety function to | ||
// construct an empty AddressContext. | ||
export function emptyAddressContext(address: string): AddressContext { | ||
export function emptyAddressContext(address: `0x${string}`): AddressContext { | ||
return { | ||
address, | ||
tokenBalances: {}, | ||
}; | ||
} | ||
|
||
// canAfford is a convenience predicate that returns true iff the | ||
// passed address context can afford to transfer the passed amount of | ||
// the token indicated by the passed token key. | ||
export function canAfford(ac: AddressContext, tk: TokenKey, amountAsBigNumberHexString: string): boolean { | ||
const tb = ac.tokenBalances[tk]; | ||
if (tb === undefined) return false; | ||
else return BigNumber.from(tb.balanceAsBigNumberHexString).gte(BigNumber.from(amountAsBigNumberHexString)); // NB here we are able to compare nominal amounts directly without worrying about units because the passed amount is denominated in the same token as the tokenbalance because both are for the passed token key | ||
} |
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
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
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