Skip to content

Commit

Permalink
rename rpc -> client for DefidRpcClient
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Mar 18, 2024
1 parent e4e8035 commit a625e91
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 56 deletions.
30 changes: 15 additions & 15 deletions apps/whale-api/src/module.api/__defid__/address.controller.defid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ async function setup (): Promise<void> {
})
await testing.generate(1)

await testing.rpc.account.accountToAccount(colAddr, { [usdcAddr]: '10000@USDC' })
await testing.client.account.accountToAccount(colAddr, { [usdcAddr]: '10000@USDC' })
await testing.generate(1)

await testing.rpc.poolpair.createPoolPair({
await testing.client.poolpair.createPoolPair({
tokenA: 'DFI',
tokenB: 'USDC',
commission: 0,
Expand All @@ -50,7 +50,7 @@ async function setup (): Promise<void> {
})
await testing.generate(1)

const poolPairsKeys = Object.keys(await testing.rpc.poolpair.listPoolPairs())
const poolPairsKeys = Object.keys(await testing.client.poolpair.listPoolPairs())
expect(poolPairsKeys.length).toStrictEqual(1)
dfiUsdc = poolPairsKeys[0]

Expand All @@ -60,13 +60,13 @@ async function setup (): Promise<void> {
await app.call('setgov', [{ LP_SPLITS: { [dfiUsdc]: 1.0 } }])
await testing.generate(1)

await testing.rpc.poolpair.addPoolLiquidity({
await testing.client.poolpair.addPoolLiquidity({
[colAddr]: '5000@DFI',
[usdcAddr]: '5000@USDC'
}, poolAddr)
await testing.generate(1)

await testing.rpc.poolpair.poolSwap({
await testing.client.poolpair.poolSwap({
from: colAddr,
tokenFrom: 'DFI',
amountFrom: 555,
Expand All @@ -75,7 +75,7 @@ async function setup (): Promise<void> {
})
await testing.generate(1)

await testing.rpc.poolpair.removePoolLiquidity(poolAddr, '2@DFI-USDC')
await testing.client.poolpair.removePoolLiquidity(poolAddr, '2@DFI-USDC')
await testing.generate(1)

// for testing same block pagination
Expand Down Expand Up @@ -761,7 +761,7 @@ describe('listTransactionsUnspent', () => {

describe('listTokens', () => {
async function setupLoanToken (): Promise<void> {
const oracleId = await testing.rpc.oracle.appointOracle(await testing.generateAddress(), [
const oracleId = await testing.client.oracle.appointOracle(await testing.generateAddress(), [
{
token: 'DFI',
currency: 'USD'
Expand All @@ -773,7 +773,7 @@ describe('listTokens', () => {
], { weightage: 1 })
await testing.generate(1)

await testing.rpc.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), {
await testing.client.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), {
prices: [
{
tokenAmount: '2@DFI',
Expand All @@ -787,12 +787,12 @@ describe('listTokens', () => {
})
await testing.generate(1)

await testing.rpc.loan.setCollateralToken({
await testing.client.loan.setCollateralToken({
token: 'DFI',
factor: new BigNumber(1),
fixedIntervalPriceId: 'DFI/USD'
})
await testing.rpc.loan.setLoanToken({
await testing.client.loan.setLoanToken({
symbol: 'LOAN',
name: 'LOAN',
fixedIntervalPriceId: 'LOAN/USD',
Expand All @@ -806,20 +806,20 @@ describe('listTokens', () => {
amount: 100
})

await testing.rpc.loan.createLoanScheme({
await testing.client.loan.createLoanScheme({
id: 'scheme',
minColRatio: 110,
interestRate: new BigNumber(1)
})
await testing.generate(1)

const vaultId = await testing.rpc.loan.createVault({
const vaultId = await testing.client.loan.createVault({
ownerAddress: await testing.address('VAULT'),
loanSchemeId: 'scheme'
})
await testing.generate(1)

await testing.rpc.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), {
await testing.client.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), {
prices: [
{
tokenAmount: '2@DFI',
Expand All @@ -833,13 +833,13 @@ describe('listTokens', () => {
})
await testing.generate(1)

await testing.rpc.loan.depositToVault({
await testing.client.loan.depositToVault({
vaultId: vaultId,
from: await testing.address('DFI'),
amount: '100@DFI'
})
await testing.generate(1)
await testing.rpc.loan.takeLoan({
await testing.client.loan.takeLoan({
vaultId: vaultId,
amounts: '10@LOAN',
to: address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('governance - listProposals and getProposal', () => {

// Create 1 CFP + 1 VOC
payoutAddress = await testing.generateAddress()
cfpProposalId = await testing.rpc.governance.createGovCfp({
cfpProposalId = await testing.client.governance.createGovCfp({
title: 'CFP proposal',
context: 'github',
amount: new BigNumber(1.23),
Expand All @@ -42,7 +42,7 @@ describe('governance - listProposals and getProposal', () => {
})
await app.generate(1)

vocProposalId = await testing.rpc.governance.createGovVoc({
vocProposalId = await testing.client.governance.createGovVoc({
title: 'VOC proposal',
context: 'github'
})
Expand Down Expand Up @@ -259,14 +259,14 @@ describe('governance - listProposalVotes', () => {
* Import the private keys of the masternode_operator in order to be able to mint blocks and vote on proposals.
* This setup uses the default masternode + two additional masternodes for a total of 3 masternodes.
*/
await testing.rpc.wallet.importPrivKey(RegTestFoundationKeys[1].owner.privKey)
await testing.rpc.wallet.importPrivKey(RegTestFoundationKeys[1].operator.privKey)
await testing.rpc.wallet.importPrivKey(RegTestFoundationKeys[2].owner.privKey)
await testing.rpc.wallet.importPrivKey(RegTestFoundationKeys[2].operator.privKey)
await testing.client.wallet.importPrivKey(RegTestFoundationKeys[1].owner.privKey)
await testing.client.wallet.importPrivKey(RegTestFoundationKeys[1].operator.privKey)
await testing.client.wallet.importPrivKey(RegTestFoundationKeys[2].owner.privKey)
await testing.client.wallet.importPrivKey(RegTestFoundationKeys[2].operator.privKey)

// Create 1 CFP + 1 VOC
payoutAddress = await testing.generateAddress()
cfpProposalId = await testing.rpc.governance.createGovCfp({
cfpProposalId = await testing.client.governance.createGovCfp({
title: 'CFP proposal',
context: 'github',
amount: new BigNumber(1.23),
Expand All @@ -275,34 +275,34 @@ describe('governance - listProposalVotes', () => {
})
await app.generate(1)

vocProposalId = await testing.rpc.governance.createGovVoc({
vocProposalId = await testing.client.governance.createGovVoc({
title: 'VOC proposal',
context: 'github'
})
await app.generate(1)

// Vote on CFP
await testing.rpc.governance.voteGov({
await testing.client.governance.voteGov({
proposalId: cfpProposalId,
masternodeId: await getVotableMasternodeId(),
decision: VoteDecision.YES
})
await app.generate(1)

// Expires cycle 1
const creationHeight = await testing.rpc.governance.getGovProposal(cfpProposalId).then(proposal => proposal.creationHeight)
const creationHeight = await testing.client.governance.getGovProposal(cfpProposalId).then(proposal => proposal.creationHeight)
const votingPeriod = 70
const cycle1 = creationHeight + (votingPeriod - creationHeight % votingPeriod) + votingPeriod
await app.generate(cycle1 - await app.getBlockCount())

// Vote on cycle 2
const masternodes = await testing.rpc.masternode.listMasternodes()
const masternodes = await testing.client.masternode.listMasternodes()
const votes = [VoteDecision.YES, VoteDecision.NO, VoteDecision.NEUTRAL]
let index = 0
for (const [id, data] of Object.entries(masternodes)) {
if (data.operatorIsMine) {
await app.generate(1, data.operatorAuthAddress) // Generate a block to operatorAuthAddress to be allowed to vote on proposal
await testing.rpc.governance.voteGov({
await testing.client.governance.voteGov({
proposalId: cfpProposalId,
masternodeId: id,
decision: votes[index]
Expand Down Expand Up @@ -388,7 +388,7 @@ describe('governance - listProposalVotes', () => {
* Return masternode that mined at least one block to vote on proposal
*/
async function getVotableMasternodeId (): Promise<string> {
const masternodes = await testing.rpc.masternode.listMasternodes()
const masternodes = await testing.client.masternode.listMasternodes()
let masternodeId = ''
for (const id in masternodes) {
const masternode = masternodes[id]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,33 +314,33 @@
// await testing.generate(1)
// }
// async function setCollateralToken (testing: Testing, symbol: string): Promise<void> {
// await testing.rpc.loan.setCollateralToken({
// await testing.client.loan.setCollateralToken({
// token: symbol,
// factor: new BigNumber(1),
// fixedIntervalPriceId: `${symbol}/USD`
// })
// await testing.generate(1)
// }
// async function setLoanToken (testing: Testing, symbol: string): Promise<void> {
// await testing.rpc.loan.setLoanToken({
// await testing.client.loan.setLoanToken({
// symbol: symbol,
// fixedIntervalPriceId: `${symbol}/USD`
// })
// await testing.generate(1)
// }
// async function createVault (testing: Testing, schemeId: string, address?: string): Promise<string> {
// const vaultId = await testing.rpc.container.call(
// const vaultId = await testing.client.container.call(
// 'createvault', [address ?? await testing.generateAddress(), schemeId]
// )
// await testing.generate(1)
// return vaultId
// }
// async function depositToVault (testing: Testing, vaultId: string, address: string, tokenAmt: string): Promise<void> {
// await testing.rpc.container.call('deposittovault', [vaultId, address, tokenAmt])
// await testing.client.container.call('deposittovault', [vaultId, address, tokenAmt])
// await testing.generate(1)
// }
// async function takeLoan (testing: Testing, vaultId: string, amounts: string | string[]): Promise<void> {
// await testing.rpc.container.call('takeloan', [{ vaultId, amounts }])
// await testing.client.container.call('takeloan', [{ vaultId, amounts }])
// await testing.generate(1)
// }
// async function placeAuctionBid (testing: Testing, vaultId: string, index: number, addr: string, tokenAmt: string): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ beforeAll(async () => {
await testing.token.create({ symbol: 'FB' })
await testing.generate(1)

const oracleId = await testing.rpc.oracle.appointOracle(await app.getNewAddress(),
const oracleId = await testing.client.oracle.appointOracle(await app.getNewAddress(),
[
{ token: 'AAPL', currency: 'USD' },
{ token: 'TSLA', currency: 'USD' },
Expand All @@ -33,54 +33,54 @@ beforeAll(async () => {
], { weightage: 1 })
await testing.generate(1)

await testing.rpc.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), {
await testing.client.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), {
prices: [{
tokenAmount: '1.5@AAPL',
currency: 'USD'
}]
})
await testing.rpc.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), {
await testing.client.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), {
prices: [{
tokenAmount: '2.5@TSLA',
currency: 'USD'
}]
})
await testing.rpc.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), {
await testing.client.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), {
prices: [{
tokenAmount: '3.5@MSFT',
currency: 'USD'
}]
})
await testing.rpc.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), {
await testing.client.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), {
prices: [{
tokenAmount: '4.5@FB',
currency: 'USD'
}]
})
await testing.generate(1)

await testing.rpc.loan.setCollateralToken({
await testing.client.loan.setCollateralToken({
token: 'AAPL',
factor: new BigNumber(0.1),
fixedIntervalPriceId: 'AAPL/USD'
})
await testing.generate(1)

await testing.rpc.loan.setCollateralToken({
await testing.client.loan.setCollateralToken({
token: 'TSLA',
factor: new BigNumber(0.2),
fixedIntervalPriceId: 'TSLA/USD'
})
await testing.generate(1)

await testing.rpc.loan.setCollateralToken({
await testing.client.loan.setCollateralToken({
token: 'MSFT',
factor: new BigNumber(0.3),
fixedIntervalPriceId: 'MSFT/USD'
})
await testing.generate(1)

await testing.rpc.loan.setCollateralToken({
await testing.client.loan.setCollateralToken({
token: 'FB',
factor: new BigNumber(0.4),
fixedIntervalPriceId: 'FB/USD'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ beforeAll(async () => {
testing = app.rpc
await app.waitForBlockHeight(101)

await testing.rpc.loan.createLoanScheme({
await testing.client.loan.createLoanScheme({
minColRatio: 100,
interestRate: new BigNumber(6.5),
id: 'default'
})
await app.generate(1)

await testing.rpc.loan.createLoanScheme({
await testing.client.loan.createLoanScheme({
minColRatio: 150,
interestRate: new BigNumber(5.5),
id: 'scheme1'
})
await app.generate(1)

await testing.rpc.loan.createLoanScheme({
await testing.client.loan.createLoanScheme({
minColRatio: 200,
interestRate: new BigNumber(4.5),
id: 'scheme2'
})
await app.generate(1)

await testing.rpc.loan.createLoanScheme({
await testing.client.loan.createLoanScheme({
minColRatio: 250,
interestRate: new BigNumber(3.5),
id: 'scheme3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ beforeAll(async () => {
], 1])
await testing.generate(1)

await testing.rpc.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), { prices: [{ tokenAmount: '1.5@AAPL', currency: 'USD' }] })
await testing.rpc.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), { prices: [{ tokenAmount: '2.5@TSLA', currency: 'USD' }] })
await testing.rpc.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), { prices: [{ tokenAmount: '3.5@MSFT', currency: 'USD' }] })
await testing.rpc.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), { prices: [{ tokenAmount: '4.5@FB', currency: 'USD' }] })
await testing.client.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), { prices: [{ tokenAmount: '1.5@AAPL', currency: 'USD' }] })
await testing.client.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), { prices: [{ tokenAmount: '2.5@TSLA', currency: 'USD' }] })
await testing.client.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), { prices: [{ tokenAmount: '3.5@MSFT', currency: 'USD' }] })
await testing.client.oracle.setOracleData(oracleId, Math.floor(new Date().getTime() / 1000), { prices: [{ tokenAmount: '4.5@FB', currency: 'USD' }] })
await testing.generate(1)

await app.call('setloantoken', [{
Expand Down
Loading

0 comments on commit a625e91

Please sign in to comment.