Skip to content

Commit

Permalink
add accessors for target symbols and weights of reserve target alloca…
Browse files Browse the repository at this point in the history
…tions. (#8481)
  • Loading branch information
aaronmgdr committed Aug 9, 2021
1 parent 7c31d37 commit 8146217
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/sdk/contractkit/src/wrappers/Reserve.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { testWithGanache } from '@celo/dev-utils/lib/ganache-test'
import BigNumber from 'bignumber.js'
import { newKitFromWeb3 } from '../kit'
import { MultiSigWrapper } from './MultiSig'
import { ReserveWrapper } from './Reserve'
Expand All @@ -22,6 +23,23 @@ testWithGanache('Reserve Wrapper', (web3) => {
reserveSpenderMultiSig = await kit.contracts.getMultiSig(multiSigAddress)
})

test('can get asset target weights which sum to 100%', async () => {
const targets = await reserve.getAssetAllocationWeights()
expect(targets.reduce((total, current) => total.plus(current), new BigNumber(0))).toEqual(
new BigNumber(100 * 10_000_000_000_000_000_000_000)
)
})

test('can get asset target symbols ', async () => {
const targets = await reserve.getAssetAllocationSymbols()

const expectation = ['cGLD', 'BTC', 'ETH', 'DAI']

targets.forEach((sym, i) => {
expect(sym).toEqual(expect.stringMatching(expectation[i]))
})
})

test('can get reserve unfrozen balance ', async () => {
const balance = await reserve.getUnfrozenBalance()
expect(balance).toEqBigNumber('1e+26')
Expand Down
20 changes: 20 additions & 0 deletions packages/sdk/contractkit/src/wrappers/Reserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ export class ReserveWrapper extends BaseWrapper<Reserve> {
valueToBigNumber
)

/**
* @notice Returns a list of weights used for the allocation of reserve assets.
* @return An array of a list of weights used for the allocation of reserve assets.
*/
getAssetAllocationWeights = proxyCall(
this.contract.methods.getAssetAllocationWeights,
undefined,
(weights) => weights.map(valueToBigNumber)
)

/**
* @notice Returns a list of token symbols that have been allocated.
* @return An array of token symbols that have been allocated.
*/
getAssetAllocationSymbols = proxyCall(
this.contract.methods.getAssetAllocationSymbols,
undefined,
(symbols) => symbols.map(this.kit.web3.utils.hexToAscii)
)

/**
* @alias {getReserveCeloBalance}
*/
Expand Down

0 comments on commit 8146217

Please sign in to comment.