Skip to content

Commit

Permalink
WIP : readme on main
Browse files Browse the repository at this point in the history
  • Loading branch information
SonYoungsung committed Jan 15, 2024
1 parent ebb035c commit 10b10f8
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 18 deletions.
120 changes: 118 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,118 @@
# titan.github.io
Unified token and contract list for Titan Mainnet and other Titan Chains.
# @titan/github

The `@titan/github` package provides a collection of tools for efficiently interacting with the Titan network.
It achieves this by providing a unified token and contract list for Titan and other chains.

## Installation

```
npm install @titan/github
```

## Quickstart Recipes

- Get all token data on each network

```javascript
import { TitanSDK } from '@titan/github'

const sdk = new TitanSDK({
chainId: 55004,
})
const tokenList = sdk.tokens
// Output the structure of the tokenList
console.log('Token List:', tokenList)

/*
The structure of the tokenList
tokenList = [
{
chainId: 55004,
address: '0x7c6b91D9Be155A6Db01f749217d76fF02A7227F2',
name: 'Tokamak Network Token',
symbol: 'TON',
decimals: 6,
logoURI: 'https://titan.github.io/data/TON/logo.svg',
extensions: {
bridgeAddress: '0x4200000000000000000000000000000000000010',
titanListId: 'default',
titanTokenId: 'TON'
}
},
{
chainId: 55004,
address: '0x0000000000000000000000000000000000000000',
name: 'Ether',
symbol: 'ETH',
decimals: 18,
logoURI: 'https://titan.github.io/data/ETH/logo.svg',
extensions: {
bridgeAddress: '0x4200000000000000000000000000000000000010',
titanListId: 'default',
titanTokenId: 'ETH'
}
},
... more token comes
]
*/
```

- Get a token contract

```javascript
import { TitanSDK } from '@titan/github'

const sdk = new TitanSDK({
chainId: 55004,
})
const TON_CONTRACT = sdk.getTokenContract('TON')
const totalSupply = await TON_CONTRACT.totalSupply()
console.log('totalSupply :', totalSupply)
// totalSupply : BigNumber { _hex: '0x24d826680754da71d432', _isBigNumber: true }
```

- Get a contract instance

```javascript
import { TitanSDK } from '@titan/github'

const sdk = new TitanSDK({
chainId: 55004,
})
const L2StandardBridge = sdk.getContract('L2StandardBridge')
const L2Messenger = await L2StandardBridge.messenger()
console.log('L2Messenger : ', L2Messenger)
// L2Messenger : 0x4200000000000000000000000000000000000007
```

## Example using CodeSandbox

You can try out the @titan/github package in an online environment using CodeSandbox. Click the button below to open the project in CodeSandbox:

[![Open in CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/your-username/your-titan-sdk-project)

This CodeSandbox project includes a basic setup with the @titan/sdk package. You can explore and experiment with the functionalities in a live environment.

## Contributing

- If you want to add a token or change to the token list, refer to [the contracts documentation]("https://github.com/tokamak-network/titan.github.io/blob/main/tokens/README.md).
- If you want to add a contract or change to the contract list, refer to [the tokens documentation]("https://github.com/tokamak-network/titan.github.io/blob/main/contracts/README.md).

## Directory Structure

```
├── contracts:
├── tokens:
├── bin:
├── test:
├── src
│ ├──
```

## Production branch

The production branch is "main". This branch holds the codebase for the most recent "stable" releases. Any changes made to the main branch are initially integrated from the develop branch.

## Development branch

The primary development branch is "develop". The develop branch includes the latest software version that remains compatible with the most recent experimental network deployments. If you're implementing a change that maintains backward compatibility, please submit your pull request to the develop branch.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Contract } from 'ethers'
import {
ContractsLike,
ERC20ContractsList,
KeyOfContractsLike,
L1ChainId,
L1Contracts,
L2ChainID,
Expand Down Expand Up @@ -120,7 +121,7 @@ export class TitanSDK {
}
}

public getContract(contractName: keyof L1Contracts | keyof L2Contracts) {
public getContract(contractName: KeyOfContractsLike) {
return getContract(contractName, this.chainId, {
signerOrProvider: this.signerOrProvider,
})
Expand Down
3 changes: 2 additions & 1 deletion src/interface/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ export type L2Contracts = {
* addresses instead of actual contract objects.
*/
export type ContractsLike = L1Contracts | L2Contracts
export type KeyOfContractsLike = keyof ContractsLike

export type ERC20ContractsList = Record<keyof ContractsLike, Contract>
export type ERC20ContractsList = Record<KeyOfContractsLike, Contract>

/**
* Stuff that can be coerced into a provider.
Expand Down
15 changes: 2 additions & 13 deletions src/utils/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,6 @@ 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,
Expand Down Expand Up @@ -125,12 +116,10 @@ export const getAllContracts = (
overrides?: DeepPartial<ContractsLike>
} = {}
): ContractsLike => {
const addresses: L1Contracts | L2Contracts = CONTRACT_ADDRESSES[
chainId
] as ContractsLike
const addresses: ContractsLike = CONTRACT_ADDRESSES[chainId] as ContractsLike

// Attach all contracts.
const contracts = {} as L1Contracts | L2Contracts
const contracts = {} as ContractsLike
for (const [contractName, contractAddress] of Object.entries(addresses)) {
contracts[contractName] = getContract(
contractName as keyof L1Contracts,
Expand Down
45 changes: 44 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,50 @@ import { ethers } from 'ethers'

import titanGithub from '../dist/index'
import { TitanSDK } from '../src'
// import {TitanSDK} from "@titan/github"

const init = async () => {}
const init = async () => {
const sdk = new TitanSDK({
chainId: 55004,
})
// const contracts = sdk.contracts
// Output the structure of the tokenList
const L2StandardBridge = sdk.getContract('L2StandardBridge')
const L2Messenger = await L2StandardBridge.messenger()
console.log('L2Messenger', L2Messenger)

/*
The structure of the tokenList
tokenList = [
{
chainId: 55004,
address: '0x7c6b91D9Be155A6Db01f749217d76fF02A7227F2',
name: 'Tokamak Network Token',
symbol: 'TON',
decimals: 6,
logoURI: 'https://titan.github.io/data/TON/logo.svg',
extensions: {
bridgeAddress: '0x4200000000000000000000000000000000000010',
titanListId: 'default',
titanTokenId: 'TON'
}
},
{
chainId: 55004,
address: '0x0000000000000000000000000000000000000000',
name: 'Ether',
symbol: 'ETH',
decimals: 18,
logoURI: 'https://titan.github.io/data/ETH/logo.svg',
extensions: {
bridgeAddress: '0x4200000000000000000000000000000000000010',
titanListId: 'default',
titanTokenId: 'ETH'
}
},
... more token comes
]
*/
}

init()

0 comments on commit 10b10f8

Please sign in to comment.