Skip to content
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
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