Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add rwa presale #66

Merged
merged 7 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
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
Loading