From ebb035c08145a02ef0ebdc818d14cb3f16935d5d Mon Sep 17 00:00:00 2001 From: SonYoungsung Date: Mon, 15 Jan 2024 16:55:27 +0900 Subject: [PATCH] Feat : SDK - contract list type --- contracts/data/tosv2/data.json | 2 +- contracts/tokamak.contractlist.json | 4 ++-- src/index.ts | 23 +++++++++++++++++++---- src/interface/types.ts | 10 ++++------ src/utils/contract.ts | 12 +++++++++++- src/utils/getList.ts | 1 + test/index.test.ts | 21 +-------------------- titan.tokenlist.json | 2 +- tokamak.contractlist.json | 2 +- 9 files changed, 41 insertions(+), 36 deletions(-) diff --git a/contracts/data/tosv2/data.json b/contracts/data/tosv2/data.json index 0fec66d..d27ddf9 100644 --- a/contracts/data/tosv2/data.json +++ b/contracts/data/tosv2/data.json @@ -11,7 +11,7 @@ "TreasuryProxy": "0xFD7C2c54a0A755a46793A91449806A4b14E3eEe8", "TOSValueCalculator": "0xDF0fCfadAF9F095C509F620A6C2BAFd7B6AD8C22" }, - "1155511": { + "11155111": { "BondDepository": "0xbBe7881cC14a509FD8F53Ce650fE065C385d98D7", "BondDepositoryProxy": "0x4d08d2113b75Bfd8B6C5D3Dd956165e1853dC6A4", "LibStaking": "0x41128bA2b9549eAf8A0D4f6b2C0b514c5b491F39", diff --git a/contracts/tokamak.contractlist.json b/contracts/tokamak.contractlist.json index 3a52ca7..f55baea 100644 --- a/contracts/tokamak.contractlist.json +++ b/contracts/tokamak.contractlist.json @@ -55,7 +55,7 @@ "55004": { "L2StandardBridge": "0x4200000000000000000000000000000000000010" }, - "1155511": { + "11155111": { "BondDepository": "0xbBe7881cC14a509FD8F53Ce650fE065C385d98D7", "BondDepositoryProxy": "0x4d08d2113b75Bfd8B6C5D3Dd956165e1853dC6A4", "LibStaking": "0x41128bA2b9549eAf8A0D4f6b2C0b514c5b491F39", @@ -67,4 +67,4 @@ "TreasuryProxy": "0xFD7C2c54a0A755a46793A91449806A4b14E3eEe8", "TOSValueCalculator": "0xDF0fCfadAF9F095C509F620A6C2BAFd7B6AD8C22" } -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index 75769ad..c1ff5a4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,8 +4,11 @@ import { Contract } from 'ethers' import { ContractsLike, + ERC20ContractsList, L1ChainId, + L1Contracts, L2ChainID, + L2Contracts, NumberLike, SignerOrProviderLike, } from './interface/types' @@ -37,8 +40,14 @@ export class TitanSDK { */ public contracts: ContractsLike + /** + * ERC20 Tokens objects from Tokens folder + */ public tokens: TokamakTokenListT - public erc20contracts + /** + * ERC20 Tokens contract objects attached to their respective providers and addresses. + */ + public erc20contracts: ERC20ContractsList /** * List of custom bridges for the given network. @@ -62,7 +71,7 @@ export class TitanSDK { l1BlockTimeSeconds?: NumberLike contracts?: DeepPartial // bridges?: BridgeAdapterData - bedrock?: boolean + // bedrock?: boolean }) { // this.signerOrProvider = toSignerOrProvider(opts.signerOrProvider) try { @@ -111,6 +120,12 @@ export class TitanSDK { } } + public getContract(contractName: keyof L1Contracts | keyof L2Contracts) { + return getContract(contractName, this.chainId, { + signerOrProvider: this.signerOrProvider, + }) + } + public getToken(symbol: string) { const result = this.tokens.filter((token) => token.symbol === symbol) if (!result || result.length > 1) { @@ -132,8 +147,8 @@ export class TitanSDK { `${symbol} token doesn't exist on this chain(id : ${this.chainId})` ) } else { - const [test] = Object.values(result) - return test + const [tokenContract] = Object.values(result) + return tokenContract as Contract } } } diff --git a/src/interface/types.ts b/src/interface/types.ts index 32e62c3..7764a01 100644 --- a/src/interface/types.ts +++ b/src/interface/types.ts @@ -1,12 +1,8 @@ -import { - Provider, - TransactionReceipt, - TransactionResponse, -} from '@ethersproject/abstract-provider' +import { Provider } from '@ethersproject/abstract-provider' import { Signer } from '@ethersproject/abstract-signer' import { Contract, BigNumber } from 'ethers' -import TokamakContractList from '../../dist/tokamak.contractlist' +import { TokamakContractList } from '../utils/getList' /* * Supported chains for the tokenlist and contractlist @@ -65,6 +61,8 @@ export type L2Contracts = { */ export type ContractsLike = L1Contracts | L2Contracts +export type ERC20ContractsList = Record + /** * Stuff that can be coerced into a provider. */ diff --git a/src/utils/contract.ts b/src/utils/contract.ts index 282b283..d45022c 100644 --- a/src/utils/contract.ts +++ b/src/utils/contract.ts @@ -7,6 +7,7 @@ import { DeepPartial } from './type-utils' import { AddressLike, ContractsLike, + ERC20ContractsList, L1Contracts, L2Contracts, } from '../interface/types' @@ -88,6 +89,15 @@ export const getContract = ( // iface = getContractInterface(name) // } + console.log('**') + console.log( + new Contract( + toAddress(opts.address || addresses[contractName] || [contractName]), + iface, + opts.signerOrProvider + ) + ) + return new Contract( toAddress(opts.address || addresses[contractName] || [contractName]), iface, @@ -146,7 +156,7 @@ export const getAllERC20Contracts = ( signerOrProvider?: ethers.Signer | ethers.providers.Provider overrides?: DeepPartial } = {} -): Record => { +): ERC20ContractsList => { // Attach all erc20 contracts. const contracts = {} for (const [, value] of Object.entries(tokenList)) { diff --git a/src/utils/getList.ts b/src/utils/getList.ts index b59c209..0d55d9a 100644 --- a/src/utils/getList.ts +++ b/src/utils/getList.ts @@ -4,3 +4,4 @@ export const TokamakTokenList = titanList.tokens.tokens export const TokamakContractList = titanList.contracts export type TokamakTokenListT = typeof TokamakTokenList +export type TokamakContractListT = typeof TokamakContractList diff --git a/test/index.test.ts b/test/index.test.ts index d46b22c..733b8ee 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -6,25 +6,6 @@ import { ethers } from 'ethers' import titanGithub from '../dist/index' import { TitanSDK } from '../src' -const getABI = (fileType) => { - const filePath = path.join('./contracts/data/bridge/abi', `${fileType}.json`) - - try { - const fileData = fs.readFileSync(filePath, 'utf8') - const abi = JSON.parse(fileData) - return abi - } catch (error) { - console.error(`Error reading ABI for _${fileType}:`, error) - return null - } -} - -const init = async () => { - // console.log(getABI('L1Bridge')) - const sdk = new TitanSDK({ chainId: 55004 }) - const contract = sdk.getTokenContract('TON') - // console.log(sdk.signer) - console.log(sdk.getTokenContract('TON')) -} +const init = async () => {} init() diff --git a/titan.tokenlist.json b/titan.tokenlist.json index 21e1214..85a1146 100644 --- a/titan.tokenlist.json +++ b/titan.tokenlist.json @@ -6,7 +6,7 @@ "layer2", "infrastructure" ], - "timestamp": "2024-01-15T06:48:21.199Z", + "timestamp": "2024-01-15T07:43:44.480Z", "tokens": [ { "chainId": 1, diff --git a/tokamak.contractlist.json b/tokamak.contractlist.json index 43c2015..f55baea 100644 --- a/tokamak.contractlist.json +++ b/tokamak.contractlist.json @@ -55,7 +55,7 @@ "55004": { "L2StandardBridge": "0x4200000000000000000000000000000000000010" }, - "1155511": { + "11155111": { "BondDepository": "0xbBe7881cC14a509FD8F53Ce650fE065C385d98D7", "BondDepositoryProxy": "0x4d08d2113b75Bfd8B6C5D3Dd956165e1853dC6A4", "LibStaking": "0x41128bA2b9549eAf8A0D4f6b2C0b514c5b491F39",