Skip to content

Commit

Permalink
add official tokens address and contract wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjah committed Oct 18, 2024
1 parent fa5345d commit f740ed4
Show file tree
Hide file tree
Showing 15 changed files with 437 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/contracts-wrappers/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './token'
export * from './tokens'
112 changes: 112 additions & 0 deletions src/contracts-wrappers/tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { Provider } from '../provider'
import { CHAIN_ID, Network } from '../utils'
import { MRC20 } from './token'

export const MAINNET_TOKENS = {
USDCe: 'AS1hCJXjndR4c9vekLWsXGnrdigp4AaZ7uYG3UKFzzKnWVsrNLPJ',
USDTb: 'AS12LKs9txoSSy8JgFJgV96m8k5z9pgzjYMYSshwN67mFVuj3bdUV',
DAIe: 'AS1ZGF1upwp9kPRvDKLxFAKRebgg7b3RWDnhgV7VvdZkZsUL7Nuv',
WETHe: 'AS124vf3YfAJCSCQVYKczzuWWpXrximFpbTmX4rheLs5uNSftiiRY',
WETHb: 'AS125oPLYRTtfVjpWisPZVTLjBhCFfQ1jDsi75XNtRm1NZux54eCj',
PUR: 'AS133eqPPaPttJ6hJnk3sfoG5cjFFqBDi1VGxdo2wzWkq8AfZnan',
}

export const BUILDNET_TOKENS = {
DAIs: 'AS12LpYyAjYRJfYhyu7fkrS224gMdvFHVEeVWoeHZzMdhis7UZ3Eb',
WETHs: 'AS1gt69gqYD92dqPyE6DBRJ7KjpnQHqFzFs2YCkBcSnuxX5bGhBC',
USDCs: 'AS12k8viVmqPtRuXzCm6rKXjLgpQWqbuMjc37YHhB452KSUUb9FgL',
USDTbt: 'AS12ix1Qfpue7BB8q6mWVtjNdNE9UV3x4MaUo7WhdUubov8sJ3CuP',
WETHbt: 'AS12RmCXTA9NZaTBUBnRJuH66AGNmtEfEoqXKxLdmrTybS6GFJPFs',
}

function checkNetwork(provider: Provider, isMainnet: boolean): void {
provider.networkInfos().then((network: Network) => {
if (isMainnet && network.chainId !== CHAIN_ID.Mainnet) {
console.warn('This contract is only available on mainnet')
} else if (!isMainnet && network.chainId === CHAIN_ID.Mainnet) {
console.warn('This contract is only available on buildnet')
}
})
}

///////////////// MAINNET TOKENS //////////////////////

export class USDCe extends MRC20 {
constructor(public provider: Provider) {
checkNetwork(provider, true)
super(provider, MAINNET_TOKENS.USDCe)
}
}

export class USDTb extends MRC20 {
constructor(public provider: Provider) {
checkNetwork(provider, true)
super(provider, MAINNET_TOKENS.USDTb)
}
}

export class DAIe extends MRC20 {
constructor(public provider: Provider) {
checkNetwork(provider, true)
super(provider, MAINNET_TOKENS.DAIe)
}
}

export class WETHe extends MRC20 {
constructor(public provider: Provider) {
checkNetwork(provider, true)
super(provider, MAINNET_TOKENS.WETHe)
}
}

export class WETHb extends MRC20 {
constructor(public provider: Provider) {
checkNetwork(provider, true)
super(provider, MAINNET_TOKENS.WETHb)
}
}

export class PUR extends MRC20 {
constructor(public provider: Provider) {
checkNetwork(provider, true)
super(provider, MAINNET_TOKENS.PUR)
}
}

///////////////// BUILDNET TOKENS //////////////////////

export class DAIs extends MRC20 {
constructor(public provider: Provider) {
checkNetwork(provider, false)
super(provider, BUILDNET_TOKENS.DAIs)
}
}

export class WETHs extends MRC20 {
constructor(public provider: Provider) {
checkNetwork(provider, false)
super(provider, BUILDNET_TOKENS.WETHs)
}
}

export class USDCs extends MRC20 {
constructor(public provider: Provider) {
checkNetwork(provider, false)
super(provider, BUILDNET_TOKENS.USDCs)
}
}

export class USDTbt extends MRC20 {
constructor(public provider: Provider) {
checkNetwork(provider, false)
super(provider, BUILDNET_TOKENS.USDTbt)
}
}

export class WETHbt extends MRC20 {
constructor(public provider: Provider) {
checkNetwork(provider, false)
super(provider, BUILDNET_TOKENS.WETHbt)
}
}
7 changes: 3 additions & 4 deletions test/integration/MRC20.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { MRC20 } from '../../src/contracts-wrappers'
import { provider } from './setup'

const USDC = 'AS12k8viVmqPtRuXzCm6rKXjLgpQWqbuMjc37YHhB452KSUUb9FgL'
describe('Generic token wrapper tests', () => {
let usdcContract: MRC20
const USDC = 'AS12k8viVmqPtRuXzCm6rKXjLgpQWqbuMjc37YHhB452KSUUb9FgL'

let usdcContract: MRC20

describe('Token wrapper tests', () => {
beforeAll(async () => {
usdcContract = new MRC20(provider, USDC)
})
Expand Down
2 changes: 2 additions & 0 deletions test/integration/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { Web3Provider } from '../../src/provider'

export let account: Account
export let provider: Web3Provider
export let mainnetProvider: Web3Provider

jest.setTimeout(120_000)

beforeAll(async () => {
account = await Account.fromEnv()
provider = Web3Provider.buildnet(account)
mainnetProvider = Web3Provider.mainnet(account)

// eslint-disable-next-line no-console
console.log(
Expand Down
29 changes: 29 additions & 0 deletions test/integration/tokens/DAIe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { DAIe } from '../../../src/contracts-wrappers'
import { mainnetProvider } from './../setup'

describe('DAIe wrapper tests', () => {
let contract: DAIe
beforeAll(async () => {
contract = new DAIe(mainnetProvider)
})

test('version', async () => {
const version = await contract.version()
expect(version).toBe('0.0.1')
})

test('name', async () => {
const name = await contract.name()
expect(name).toBe('Dai Stablecoin')
})

test('symbol', async () => {
const symbol = await contract.symbol()
expect(symbol).toBe('DAI.e')
})

test('decimals', async () => {
const decimals = await contract.decimals()
expect(decimals).toBe(18)
})
})
29 changes: 29 additions & 0 deletions test/integration/tokens/DAIs.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { DAIs } from '../../../src/contracts-wrappers'
import { provider } from './../setup'

describe('DAIs wrapper tests', () => {
let contract: DAIs
beforeAll(async () => {
contract = new DAIs(provider)
})

test('version', async () => {
const version = await contract.version()
expect(version).toBe('0.0.1')
})

test('name', async () => {
const name = await contract.name()
expect(name).toBe('Sepolia tDAI')
})

test('symbol', async () => {
const symbol = await contract.symbol()
expect(symbol).toBe('tDAI.s')
})

test('decimals', async () => {
const decimals = await contract.decimals()
expect(decimals).toBe(18)
})
})
29 changes: 29 additions & 0 deletions test/integration/tokens/PUR.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { PUR } from '../../../src/contracts-wrappers'
import { mainnetProvider } from './../setup'

describe('PUR wrapper tests', () => {
let contract: PUR
beforeAll(async () => {
contract = new PUR(mainnetProvider)
})

test('version', async () => {
const version = await contract.version()
expect(version).toBe('0.0.1')
})

test('name', async () => {
const name = await contract.name()
expect(name).toBe('Purrfect Universe')
})

test('symbol', async () => {
const symbol = await contract.symbol()
expect(symbol).toBe('PUR')
})

test('decimals', async () => {
const decimals = await contract.decimals()
expect(decimals).toBe(18)
})
})
29 changes: 29 additions & 0 deletions test/integration/tokens/USDCe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { USDCe } from '../../../src/contracts-wrappers'
import { mainnetProvider } from './../setup'

describe('USDCe wrapper tests', () => {
let contract: USDCe
beforeAll(async () => {
contract = new USDCe(mainnetProvider)
})

test('version', async () => {
const version = await contract.version()
expect(version).toBe('0.0.1')
})

test('name', async () => {
const name = await contract.name()
expect(name).toBe('USD Coin')
})

test('symbol', async () => {
const symbol = await contract.symbol()
expect(symbol).toBe('USDC.e')
})

test('decimals', async () => {
const decimals = await contract.decimals()
expect(decimals).toBe(6)
})
})
29 changes: 29 additions & 0 deletions test/integration/tokens/USDCs.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { USDCs } from '../../../src/contracts-wrappers'
import { provider } from './../setup'

describe('USDCs wrapper tests', () => {
let contract: USDCs
beforeAll(async () => {
contract = new USDCs(provider)
})

test('version', async () => {
const version = await contract.version()
expect(version).toBe('0.0.1')
})

test('name', async () => {
const name = await contract.name()
expect(name).toBe('Sepolia USDC')
})

test('symbol', async () => {
const symbol = await contract.symbol()
expect(symbol).toBe('USDC.s')
})

test('decimals', async () => {
const decimals = await contract.decimals()
expect(decimals).toBe(6)
})
})
29 changes: 29 additions & 0 deletions test/integration/tokens/USDTb.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { USDTb } from '../../../src/contracts-wrappers'
import { mainnetProvider } from './../setup'

describe('USDTb wrapper tests', () => {
let contract: USDTb
beforeAll(async () => {
contract = new USDTb(mainnetProvider)
})

test('version', async () => {
const version = await contract.version()
expect(version).toBe('0.0.1')
})

test('name', async () => {
const name = await contract.name()
expect(name).toBe('Bsc USDT')
})

test('symbol', async () => {
const symbol = await contract.symbol()
expect(symbol).toBe('USDT.b')
})

test('decimals', async () => {
const decimals = await contract.decimals()
expect(decimals).toBe(18)
})
})
29 changes: 29 additions & 0 deletions test/integration/tokens/USDTbt.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { USDTbt } from '../../../src/contracts-wrappers'
import { provider } from './../setup'

describe('USDTbt wrapper tests', () => {
let contract: USDTbt
beforeAll(async () => {
contract = new USDTbt(provider)
})

test('version', async () => {
const version = await contract.version()
expect(version).toBe('0.0.1')
})

test('name', async () => {
const name = await contract.name()
expect(name).toBe('Binance-peg USD')
})

test('symbol', async () => {
const symbol = await contract.symbol()
expect(symbol).toBe('USDT.bt')
})

test('decimals', async () => {
const decimals = await contract.decimals()
expect(decimals).toBe(18)
})
})
29 changes: 29 additions & 0 deletions test/integration/tokens/WETHb.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { WETHb } from '../../../src/contracts-wrappers'
import { mainnetProvider } from './../setup'

describe('WETH.b wrapper tests', () => {
let contract: WETHb
beforeAll(async () => {
contract = new WETHb(mainnetProvider)
})

test('version', async () => {
const version = await contract.version()
expect(version).toBe('0.0.1')
})

test('name', async () => {
const name = await contract.name()
expect(name).toBe('Bsc ETH')
})

test('symbol', async () => {
const symbol = await contract.symbol()
expect(symbol).toBe('WETH.b')
})

test('decimals', async () => {
const decimals = await contract.decimals()
expect(decimals).toBe(18)
})
})
Loading

1 comment on commit f740ed4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report for experimental massa-web3

St.
Category Percentage Covered / Total
🟡 Statements 64.42% 1146/1779
🔴 Branches 46.76% 195/417
🔴 Functions 47.84% 210/439
🟡 Lines 64.72% 1139/1760

Test suite run success

131 tests passing in 14 suites.

Report generated by 🧪jest coverage report action from f740ed4

Please sign in to comment.