Skip to content

Commit

Permalink
Merge pull request #66 from IndexCoop/feat/add-rwa-presale
Browse files Browse the repository at this point in the history
feat: add rwa presale
  • Loading branch information
janndriessen authored Jun 19, 2024
2 parents f55bc02 + 0d48fd5 commit 9f46e9a
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 4 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ jobs:
- run: npm run test:builders
- run: npm run test:quotes
- run: npm run test:hyeth
- run: npm run test:rwa
- run: npm run test:btc2x
- run: npm run test:cdeti
- run: npm run test:dseth
- run: npm run test:eth2x
- run: npm run test:gtceth
- run: npm run test:iceth
# - run: npm run test:eth2x
# - run: npm run test:gtceth
# - run: npm run test:iceth
# - run: npm run test:icreth
# run last - as it alters the block number
# skip as it can't be minted or redeemed with 0x
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"test:eth2xfli": "npm test src/tests/eth2xfli",
"test:gtceth": "npm test src/tests/gtceth",
"test:hyeth": "npm test src/tests/hyeth.test.ts",
"test:rwa": "npm test src/tests/rwa.presale.test.ts",
"test:iceth": "npm test src/tests/iceth",
"test:icreth": "npm test src/tests/icreth",
"test:watch": "jest --watch"
Expand Down
5 changes: 5 additions & 0 deletions src/constants/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ export const MetaverseIndex: Token = {
symbol: 'MVI',
}

export const RealWorldAssetIndex: Token = {
address: '0x7f5f1A44dd6f88cCb54Fe879e144dF644A4aDa24',
symbol: 'RWA',
}

// Other

export const DAI: Token = {
Expand Down
9 changes: 9 additions & 0 deletions src/quote/provider/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
InterestCompoundingETHIndex,
LeveragedrEthStakingYield,
MetaverseIndex,
RealWorldAssetIndex,
} from 'constants/tokens'

import { FlashMintContractType } from './'
Expand Down Expand Up @@ -153,4 +154,12 @@ describe('getContractType()', () => {
)
expect(contractType).toBe(FlashMintContractType.leveraged)
})

test('returns correct contract type for RWA', async () => {
const contractType = getContractType(
RealWorldAssetIndex.symbol,
ChainId.Mainnet
)
expect(contractType).toBe(FlashMintContractType.zeroEx)
})
})
4 changes: 3 additions & 1 deletion src/quote/provider/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
InterestCompoundingETHIndex,
LeveragedrEthStakingYield,
MetaverseIndex,
RealWorldAssetIndex,
} from 'constants/tokens'

import { FlashMintContractType } from './index'
Expand Down Expand Up @@ -46,7 +47,8 @@ export function getContractType(
token === DefiPulseIndex.symbol ||
token === DiversifiedStakedETHIndex.symbol ||
token === GitcoinStakedETHIndex.symbol ||
token === MetaverseIndex.symbol
token === MetaverseIndex.symbol ||
token === RealWorldAssetIndex.symbol
)
return FlashMintContractType.zeroEx
if (
Expand Down
73 changes: 73 additions & 0 deletions src/tests/rwa.presale.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {
getMainnetTestFactory,
QuoteTokens,
SignerAccount4,
TestFactory,
transferFromWhale,
wei,
wrapETH,
} from './utils'

const { eth, rwa, usdc, weth } = QuoteTokens

describe('RWA presale', () => {
const indexToken = rwa
const signer = SignerAccount4
let factory: TestFactory
beforeEach(async () => {
factory = getMainnetTestFactory(signer)
})

test('can mint with ETH', async () => {
await factory.fetchQuote({
isMinting: true,
inputToken: eth,
outputToken: indexToken,
indexTokenAmount: wei('1'),
slippage: 0.5,
})
await factory.executeTx()
})

test('can mint with WETH', async () => {
const quote = await factory.fetchQuote({
isMinting: true,
inputToken: weth,
outputToken: indexToken,
indexTokenAmount: wei('1'),
slippage: 0.5,
})
await wrapETH(quote.inputAmount, signer)
await factory.executeTx()
})

test('can mint with USDC', async () => {
const quote = await factory.fetchQuote({
isMinting: true,
inputToken: usdc,
outputToken: indexToken,
indexTokenAmount: wei('1'),
slippage: 0.5,
})
const whale = '0x7713974908Be4BEd47172370115e8b1219F4A5f0'
await transferFromWhale(
whale,
factory.getSigner().address,
wei('10000', quote.inputToken.decimals),
quote.inputToken.address,
factory.getProvider()
)
await factory.executeTx()
})

test('can redeem to USDC', async () => {
await factory.fetchQuote({
isMinting: false,
inputToken: indexToken,
outputToken: usdc,
indexTokenAmount: wei('1'),
slippage: 0.5,
})
await factory.executeTx()
})
})
9 changes: 9 additions & 0 deletions src/tests/utils/quoteTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
LeveragedrEthStakingYield,
MetaverseIndex,
RETH,
RealWorldAssetIndex,
USDC,
USDT,
WETH,
Expand Down Expand Up @@ -113,6 +114,13 @@ const reth: QuoteToken = {
decimals: 18,
symbol: RETH.symbol,
}

const rwa: QuoteToken = {
address: RealWorldAssetIndex.address!,
decimals: 18,
symbol: RealWorldAssetIndex.symbol,
}

const seth2: QuoteToken = {
address: sETH2.address!,
decimals: 18,
Expand Down Expand Up @@ -165,6 +173,7 @@ export const QuoteTokens = {
icreth,
mvi,
reth,
rwa,
seth2,
steth,
usdc,
Expand Down
19 changes: 19 additions & 0 deletions src/utils/contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
IndexCoopBitcoin3xIndex,
IndexCoopInverseEthereumIndex,
IndexCoopInverseBitcoinIndex,
RealWorldAssetIndex,
} from 'constants/tokens'

import {
Expand Down Expand Up @@ -459,3 +460,21 @@ describe('iETH1x', () => {
expect(contract.functions.issueExactSetFromETH).toBeDefined()
})
})

describe('RWA', () => {
test('return correct contract for token - arbitrum', async () => {
const expectedAddress = FlashMintZeroExMainnetAddress
const contract = getFlashMintZeroExContractForToken(
RealWorldAssetIndex.symbol,
undefined,
ChainId.Mainnet
)
expect(contract.address).toEqual(expectedAddress)
expect(contract.functions.getRequiredIssuanceComponents).toBeDefined()
expect(contract.functions.getRequiredRedemptionComponents).toBeDefined()
expect(contract.functions.issueExactSetFromETH).toBeDefined()
expect(contract.functions.issueExactSetFromToken).toBeDefined()
expect(contract.functions.redeemExactSetForETH).toBeDefined()
expect(contract.functions.redeemExactSetForToken).toBeDefined()
})
})
2 changes: 2 additions & 0 deletions src/utils/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
IndexCoopEthereum3xIndex,
IndexCoopInverseBitcoinIndex,
IndexCoopInverseEthereumIndex,
RealWorldAssetIndex,
} from '../constants/tokens'

export function getExchangeIssuanceLeveragedContractAddress(
Expand Down Expand Up @@ -217,6 +218,7 @@ export const getFlashMintZeroExContractForToken = (
case CoinDeskEthTrendIndex.symbol:
case DiversifiedStakedETHIndex.symbol:
case GitcoinStakedETHIndex.symbol:
case RealWorldAssetIndex.symbol:
case wsETH2.symbol:
return new Contract(
FlashMintZeroExMainnetAddress,
Expand Down
8 changes: 8 additions & 0 deletions src/utils/issuanceModules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
IndexCoopBitcoin2xIndex,
IndexCoopBitcoin3xIndex,
HighYieldETHIndex,
RealWorldAssetIndex,
} from 'constants/tokens'

import { getIssuanceModule } from './issuanceModules'
Expand Down Expand Up @@ -78,6 +79,13 @@ describe('getIssuanceModule() - Mainnet - IndexProtocol', () => {
expect(issuanceModule.isDebtIssuance).toBe(true)
})

test('returns debt issuance module v2 for RWA', async () => {
const expectedModule = IndexDebtIssuanceModuleV2Address_v2
const issuanceModule = getIssuanceModule(RealWorldAssetIndex.symbol)
expect(issuanceModule.address).toEqual(expectedModule)
expect(issuanceModule.isDebtIssuance).toBe(true)
})

test('returns debt issuance module v2 for wsETH2', async () => {
const expectedModule = IndexDebtIssuanceModuleV2Address
const issuanceModule = getIssuanceModule(wsETH2.symbol)
Expand Down
2 changes: 2 additions & 0 deletions src/utils/issuanceModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
IndexCoopEthereum2xIndex,
IndexCoopBitcoin2xIndex,
HighYieldETHIndex,
RealWorldAssetIndex,
} from '../constants/tokens'

export interface IssuanceModule {
Expand Down Expand Up @@ -53,6 +54,7 @@ export function getIssuanceModule(
case IndexCoopBitcoin2xIndex.symbol:
case IndexCoopEthereum2xIndex.symbol:
case LeveragedrEthStakingYield.symbol:
case RealWorldAssetIndex.symbol:
return {
address: IndexDebtIssuanceModuleV2Address_v2,
isDebtIssuance: true,
Expand Down

0 comments on commit 9f46e9a

Please sign in to comment.