Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XC subgraph and sdk #5

Merged
merged 3 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 52 additions & 18 deletions sdk/examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@ import {
getAmpleforthCPIOracle,
getOracleProviderReports,
getAmpleforthPolicy,
getRebaseReports,
getRebases,
getAMPLToken,
getTokenBalance,
getTokenApproval,
getXCAmpleController,
getXCRebases,
getXCAmpleToken,
} from '../src'

async function run() {
async function printAMPLData(chainID: number) {
console.log('------------------------')
console.log('chainID', chainID)
const now = Date.now() / 1000
const marketOracle = await getAmpleforthMarketOracle()

const marketOracle = await getAmpleforthMarketOracle(chainID)
console.log('Market oracle', marketOracle.getData().toString())
console.log('Providers ', marketOracle.providers.length)

const cpiOracle = await getAmpleforthCPIOracle()
const cpiOracle = await getAmpleforthCPIOracle(chainID)
console.log('CPI oracle', cpiOracle.getData().toString())
console.log('Providers ', cpiOracle.providers.length)

const policy = await getAmpleforthPolicy()
const policy = await getAmpleforthPolicy(chainID)
console.log('Epoch', policy.epoch.toString())
console.log('Supply', policy.supply.toString())

Expand All @@ -35,41 +41,69 @@ async function run() {
if (cpi && rate) {
console.log(
'Next rebase perc',
policy.nextRebasePerc(rate.toString(), cpi.toString()),
policy.nextRebasePerc(rate.toString(), cpi.toString()).toString(),
)
}

console.log(
'Rebase perc',
policy
.nextRebasePerc('1.2507983570213292', '116.78800000000001')
.toString(),
)

const ampl = await getAMPLToken()
console.log('AMPL supply', ampl.totalSupply.toString())
const ampl = await getAMPLToken(chainID)
const b = await getTokenBalance(
ampl,
'0x6723b7641c8ac48a61f5f505ab1e9c03bb44a301',
chainID,
)
console.log('User Balance', b.balance.toString())

const a = await getTokenApproval(
ampl,
'0xd99528ce2a83fbad03c1b50bb39e5653b91072b3',
'0x881d40237659c251811cec9c364ef91dc08d300c',
chainID,
)
console.log('User Approval', a.value.toString())

// history
const providerReports = await getOracleProviderReports(
marketOracle,
marketOracle.providers[0].id,
chainID,
)
console.log('Provider reports', providerReports.length)

const rebases = await getRebases(policy, chainID)
console.log('Rebases', rebases.length)
}

async function printXCAmpleData(chainID: number) {
console.log('------------------------')
console.log('chainID', chainID)

const xcController = await getXCAmpleController(chainID)
console.log('Epoch', xcController.epoch.toString())
console.log('Supply', xcController.supply.toString())

const xcAmple = await getXCAmpleToken(chainID)
const b = await getTokenBalance(
xcAmple,
'0xe36ae366692acbf696715b6bddce0938398dd991',
chainID,
)
console.log('User Balance', b.balance.toString())

const a = await getTokenApproval(
xcAmple,
'0xa308de214e01c365834e3344c1088b0d2b97559c',
'0xe36ae366692acbf696715b6bddce0938398dd991',
chainID,
)
console.log(providerReports.length)
console.log('User Approval', a.value.toString())

const rebases = await getRebaseReports(policy)
const rebases = await getXCRebases(xcController, chainID)
console.log('Rebases', rebases.length)
}

async function run() {
await printAMPLData(1)
await printXCAmpleData(43114)
await printAMPLData(42)
}

run()
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ampleforthorg/sdk",
"version": "1.0.11",
"version": "1.0.12",
"description": "Typescript SDK for the Ampleforth Protocol",
"license": "GPL-3.0-or-later",
"main": "dist/src/index.js",
Expand Down
Loading