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 btc2x #46

Merged
merged 8 commits into from
Mar 13, 2024
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
5 changes: 3 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ jobs:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run lint
- run: npm run build --if-present
- run: npm run hardhat & npm run test:btc2x
- run: npm run hardhat & npm run test:cdeti
- run: npm run hardhat & npm run test:dseth
- run: npm run hardhat & npm run test:eth2x
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"lint": "prettier -c . && eslint ./src",
"lint:fix": "prettier -w . && eslint ./src --fix",
"test": "jest",
"test:btc2x": "npm test src/tests/btc2x.test.ts",
"test:cdeti": "npm test src/tests/cdeti",
"test:dseth": "npm test src/tests/dseth",
"test:eth2x": "npm test src/tests/eth2x.test.ts",
Expand Down
7 changes: 6 additions & 1 deletion src/constants/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ export const GitcoinStakedETHIndex: Token = {
symbol: 'gtcETH',
}

export const IndexCoopBitcoin2xIndex: Token = {
address: '0xD2AC55cA3Bbd2Dd1e9936eC640dCb4b745fDe759',
symbol: 'BTC2X',
}

export const IndexCoopEthereum2xIndex: Token = {
address: '0x31F13653433B6c48fD5B19945cD9ab20621F8d4B',
address: '0x65c4C0517025Ec0843C9146aF266A2C5a2D148A2',
symbol: 'ETH2X',
}

Expand Down
2 changes: 2 additions & 0 deletions src/quote/indexQuoteProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
DiversifiedStakedETHIndex,
ETH2xFlexibleLeverageIndex,
GitcoinStakedETHIndex,
IndexCoopBitcoin2xIndex,
IndexCoopEthereum2xIndex,
InterestCompoundingETHIndex,
LeveragedrEthStakingYield,
Expand Down Expand Up @@ -178,6 +179,7 @@ function getContractType(token: string): FlashMintContractType | null {
if (
token === BTC2xFlexibleLeverageIndex.symbol ||
token === ETH2xFlexibleLeverageIndex.symbol ||
token === IndexCoopBitcoin2xIndex.symbol ||
token === IndexCoopEthereum2xIndex.symbol ||
token === InterestCompoundingETHIndex.symbol ||
token === LeveragedrEthStakingYield.symbol
Expand Down
42 changes: 42 additions & 0 deletions src/tests/btc2x.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
LocalhostProvider,
QuoteTokens,
SignerAccount4,
TestFactory,
wei,
ZeroExApiSwapQuote,
} from './utils'

const { btc2x, eth } = QuoteTokens
const zeroExApi = ZeroExApiSwapQuote

describe('BTC2X (mainnet)', () => {
let factory: TestFactory
beforeEach(async () => {
const provider = LocalhostProvider
const signer = SignerAccount4
factory = new TestFactory(provider, signer, zeroExApi)
})

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

test('can redeem with ETH', async () => {
await factory.fetchQuote({
isMinting: false,
inputToken: btc2x,
outputToken: eth,
indexTokenAmount: wei('1'),
slippage: 0.5,
})
await factory.executeTx()
})
})
8 changes: 8 additions & 0 deletions src/tests/utils/quoteTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ETH,
ETH2xFlexibleLeverageIndex,
GitcoinStakedETHIndex,
IndexCoopBitcoin2xIndex,
IndexCoopEthereum2xIndex,
InterestCompoundingETHIndex,
LeveragedrEthStakingYield,
Expand All @@ -22,6 +23,12 @@ import {
} from 'constants/tokens'
import { QuoteToken } from 'quote/quoteToken'

const btc2x: QuoteToken = {
address: IndexCoopBitcoin2xIndex.address!,
decimals: 18,
symbol: IndexCoopBitcoin2xIndex.symbol,
}

const btc2xfli: QuoteToken = {
address: BTC2xFlexibleLeverageIndex.address!,
decimals: 18,
Expand Down Expand Up @@ -136,6 +143,7 @@ const wseth: QuoteToken = {
}

export const QuoteTokens = {
btc2x,
btc2xfli,
cdeti,
dai,
Expand Down
17 changes: 17 additions & 0 deletions src/utils/contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
LeveragedrEthStakingYield,
CoinDeskEthTrendIndex,
IndexCoopEthereum2xIndex,
IndexCoopBitcoin2xIndex,
} from 'constants/tokens'

import {
Expand Down Expand Up @@ -292,6 +293,22 @@ describe('getFlashMintZeroExContractForToken()', () => {
})
})

describe('BTC2X', () => {
test('return correct contract for token', async () => {
const expectedAddress = FlashMintLeveragedAddress
const contract = getFlashMintLeveragedContractForToken(
IndexCoopBitcoin2xIndex.symbol,
undefined
)
expect(contract.address).toEqual(expectedAddress)
expect(contract.functions.getLeveragedTokenData).toBeDefined()
expect(contract.functions.issueExactSetFromERC20).toBeDefined()
expect(contract.functions.issueExactSetFromETH).toBeDefined()
expect(contract.functions.redeemExactSetForERC20).toBeDefined()
expect(contract.functions.redeemExactSetForETH).toBeDefined()
})
})

describe('ETH2X', () => {
test('return correct contract for token', async () => {
const expectedAddress = FlashMintLeveragedAddress
Expand Down
2 changes: 2 additions & 0 deletions src/utils/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
LeveragedrEthStakingYield,
CoinDeskEthTrendIndex,
IndexCoopEthereum2xIndex,
IndexCoopBitcoin2xIndex,
} from '../constants/tokens'

export function getExchangeIssuanceLeveragedContractAddress(
Expand Down Expand Up @@ -111,6 +112,7 @@ export const getFlashMintLeveragedContractForToken = (
case BTC2xFlexibleLeverageIndex.symbol:
case ETH2xFlexibleLeverageIndex.symbol:
return getFlashMintLeveragedForCompoundContract(signerOrProvider)
case IndexCoopBitcoin2xIndex.symbol:
case IndexCoopEthereum2xIndex.symbol:
case LeveragedrEthStakingYield.symbol:
return getIndexFlashMintLeveragedContract(signerOrProvider)
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 @@ -20,11 +20,19 @@ import {
LeveragedrEthStakingYield,
CoinDeskEthTrendIndex,
IndexCoopEthereum2xIndex,
IndexCoopBitcoin2xIndex,
} from 'constants/tokens'

import { getIssuanceModule } from './issuanceModules'

describe('getIssuanceModule() - Mainnet - IndexProtocol', () => {
test('returns debt issuance module v2 for BTC2X', async () => {
const expectedModule = IndexDebtIssuanceModuleV2Address_v2
const issuanceModule = getIssuanceModule(IndexCoopBitcoin2xIndex.symbol)
expect(issuanceModule.address).toEqual(expectedModule)
expect(issuanceModule.isDebtIssuance).toBe(true)
})

test('returns debt issuance module v2 for cdETI', async () => {
const expectedModule = IndexDebtIssuanceModuleV2Address_v2
const issuanceModule = getIssuanceModule(CoinDeskEthTrendIndex.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 @@ -17,6 +17,7 @@ import {
LeveragedrEthStakingYield,
CoinDeskEthTrendIndex,
IndexCoopEthereum2xIndex,
IndexCoopBitcoin2xIndex,
} from '../constants/tokens'

export interface IssuanceModule {
Expand All @@ -40,6 +41,7 @@ export function getIssuanceModule(
case ETH2xFlexibleLeverageIndex.symbol:
return { address: DebtIssuanceModuleAddress, isDebtIssuance: true }
case CoinDeskEthTrendIndex.symbol:
case IndexCoopBitcoin2xIndex.symbol:
case IndexCoopEthereum2xIndex.symbol:
case LeveragedrEthStakingYield.symbol:
return {
Expand Down
Loading