|
| 1 | +import "module-alias/register"; |
| 2 | +import { BigNumber } from "@ethersproject/bignumber"; |
| 3 | + |
| 4 | +import { Address } from "@utils/types"; |
| 5 | +import { Account } from "@utils/test/types"; |
| 6 | +import { ADDRESS_ZERO, ZERO } from "@utils/constants"; |
| 7 | +import { |
| 8 | + AGIMigrationWrapAdapter, |
| 9 | + SetToken, |
| 10 | + SingularityNetToken, |
| 11 | + StandardTokenMock, |
| 12 | + WrapModule |
| 13 | +} from "@utils/contracts"; |
| 14 | +import DeployHelper from "@utils/deploys"; |
| 15 | +import { |
| 16 | + ether, |
| 17 | +} from "@utils/index"; |
| 18 | +import { |
| 19 | + addSnapshotBeforeRestoreAfterEach, |
| 20 | + getAccounts, |
| 21 | + getWaffleExpect, |
| 22 | + getSystemFixture, |
| 23 | +} from "@utils/test/index"; |
| 24 | +import { SystemFixture } from "@utils/fixtures"; |
| 25 | + |
| 26 | +const expect = getWaffleExpect(); |
| 27 | + |
| 28 | +describe("AGIMigrationWrapModule", () => { |
| 29 | + let owner: Account; |
| 30 | + let deployer: DeployHelper; |
| 31 | + let setup: SystemFixture; |
| 32 | + |
| 33 | + let wrapModule: WrapModule; |
| 34 | + let agiMigrationWrapAdapter: AGIMigrationWrapAdapter; |
| 35 | + let agiToken: SingularityNetToken; |
| 36 | + let agixToken: StandardTokenMock; |
| 37 | + |
| 38 | + const agiMigrationWrapAdapterIntegrationName: string = "AGI_MIGRATION_WRAPPER"; |
| 39 | + |
| 40 | + before(async () => { |
| 41 | + [ |
| 42 | + owner, |
| 43 | + ] = await getAccounts(); |
| 44 | + |
| 45 | + // System setup |
| 46 | + deployer = new DeployHelper(owner.wallet); |
| 47 | + setup = getSystemFixture(owner.address); |
| 48 | + await setup.initialize(); |
| 49 | + |
| 50 | + // WrapModule setup |
| 51 | + wrapModule = await deployer.modules.deployWrapModule(setup.controller.address, setup.weth.address); |
| 52 | + await setup.controller.addModule(wrapModule.address); |
| 53 | + |
| 54 | + // Deploy AGI and AGIX token |
| 55 | + agiToken = await deployer.external.deploySingularityNetToken(); |
| 56 | + agixToken = await deployer.mocks.deployTokenMock(owner.address); |
| 57 | + |
| 58 | + // AaveMigrationWrapAdapter setup |
| 59 | + agiMigrationWrapAdapter = await deployer.adapters.deployAGIMigrationWrapAdapter( |
| 60 | + agiToken.address, |
| 61 | + agixToken.address |
| 62 | + ); |
| 63 | + |
| 64 | + await setup.integrationRegistry.addIntegration(wrapModule.address, agiMigrationWrapAdapterIntegrationName, agiMigrationWrapAdapter.address); |
| 65 | + }); |
| 66 | + |
| 67 | + addSnapshotBeforeRestoreAfterEach(); |
| 68 | + |
| 69 | + context("when a SetToken has been deployed and issued", async () => { |
| 70 | + let setToken: SetToken; |
| 71 | + let setTokensIssued: BigNumber; |
| 72 | + |
| 73 | + before(async () => { |
| 74 | + setToken = await setup.createSetToken( |
| 75 | + [agiToken.address], |
| 76 | + [BigNumber.from(10 ** 8)], |
| 77 | + [setup.issuanceModule.address, wrapModule.address] |
| 78 | + ); |
| 79 | + |
| 80 | + // Initialize modules |
| 81 | + await setup.issuanceModule.initialize(setToken.address, ADDRESS_ZERO); |
| 82 | + await wrapModule.initialize(setToken.address); |
| 83 | + |
| 84 | + // Issue some Sets |
| 85 | + setTokensIssued = ether(10); |
| 86 | + const underlyingRequired = setTokensIssued.div(10 ** 10); |
| 87 | + await agiToken.approve(setup.issuanceModule.address, underlyingRequired); |
| 88 | + |
| 89 | + await setup.issuanceModule.issue(setToken.address, setTokensIssued, owner.address); |
| 90 | + }); |
| 91 | + |
| 92 | + describe("#wrap", async () => { |
| 93 | + let subjectSetToken: Address; |
| 94 | + let subjectUnderlyingToken: Address; |
| 95 | + let subjectWrappedToken: Address; |
| 96 | + let subjectUnderlyingUnits: BigNumber; |
| 97 | + let subjectIntegrationName: string; |
| 98 | + let subjectCaller: Account; |
| 99 | + |
| 100 | + beforeEach(async () => { |
| 101 | + subjectSetToken = setToken.address; |
| 102 | + subjectUnderlyingToken = agiToken.address; |
| 103 | + subjectWrappedToken = agixToken.address; |
| 104 | + subjectUnderlyingUnits = BigNumber.from(10 ** 8); |
| 105 | + subjectIntegrationName = agiMigrationWrapAdapterIntegrationName; |
| 106 | + subjectCaller = owner; |
| 107 | + }); |
| 108 | + |
| 109 | + async function subject(): Promise<any> { |
| 110 | + return wrapModule.connect(subjectCaller.wallet).wrap( |
| 111 | + subjectSetToken, |
| 112 | + subjectUnderlyingToken, |
| 113 | + subjectWrappedToken, |
| 114 | + subjectUnderlyingUnits, |
| 115 | + subjectIntegrationName, |
| 116 | + ); |
| 117 | + } |
| 118 | + |
| 119 | + it("should reduce the zero out the AGI unit and remove token from components", async () => { |
| 120 | + const previousUnderlyingBalance = await agiToken.balanceOf(setToken.address); |
| 121 | + |
| 122 | + await subject(); |
| 123 | + |
| 124 | + const underlyingBalance = await agiToken.balanceOf(setToken.address); |
| 125 | + const agiTokenUnit = await setToken.getDefaultPositionRealUnit(agiToken.address); |
| 126 | + const agxTokenUnit = await setToken.getDefaultPositionRealUnit(agixToken.address); |
| 127 | + const components = await setToken.getComponents(); |
| 128 | + |
| 129 | + const expectedUnderlyingBalance = previousUnderlyingBalance.sub(setTokensIssued.div(10 ** 10)); |
| 130 | + expect(underlyingBalance).to.eq(expectedUnderlyingBalance); |
| 131 | + expect(agiTokenUnit).to.eq(ZERO); |
| 132 | + expect(agxTokenUnit).to.eq(ZERO); |
| 133 | + expect(components.length).to.eq(ZERO); |
| 134 | + }); |
| 135 | + }); |
| 136 | + }); |
| 137 | +}); |
0 commit comments