-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add logic to get tokens balances for chain and address, change getBal…
…ance and getDecimals to work without signer
- Loading branch information
Showing
12 changed files
with
180 additions
and
62 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { ContractConfig } from '@moonbeam-network/xcm-builder'; | ||
import { Chain, PublicClient, createPublicClient, http } from 'viem'; | ||
import { BalanceContractInterface } from '../../contract.interfaces'; | ||
import abi from './Erc20ABI.json'; | ||
|
||
export class Erc20Public implements BalanceContractInterface { | ||
readonly address: string; | ||
|
||
readonly #config: ContractConfig; | ||
|
||
readonly #publicClient: PublicClient; | ||
|
||
constructor(config: ContractConfig, chain: Chain) { | ||
if (!config.address) { | ||
throw new Error('Contract address is required'); | ||
} | ||
this.address = config.address; | ||
|
||
this.#config = config; | ||
|
||
this.#publicClient = createPublicClient({ | ||
chain, | ||
transport: http(), | ||
}); | ||
} | ||
|
||
async getBalance(): Promise<bigint> { | ||
const data = await this.#publicClient.readContract({ | ||
abi, | ||
address: this.#config.address as `0x${string}`, | ||
functionName: 'balanceOf', | ||
}); | ||
|
||
return data as unknown as bigint; | ||
} | ||
|
||
async getDecimals(): Promise<number> { | ||
const data = await this.#publicClient.readContract({ | ||
abi, | ||
address: this.#config.address as `0x${string}`, | ||
functionName: 'decimals', | ||
}); | ||
|
||
return data as unknown as number; | ||
} | ||
} |
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
Oops, something went wrong.