-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: combine Usual 1:1 pricing in one integration
- Loading branch information
1 parent
8a8dfcf
commit 16ea063
Showing
9 changed files
with
828 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Address } from '../../types'; | ||
|
||
export type PoolState = {}; | ||
|
||
export type UsualBondData = {}; | ||
|
||
export type DexParams = { | ||
fromToken: { address: Address; decimals: number }; | ||
toToken: { address: Address; decimals: number }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
Address, | ||
NumberAsString, | ||
DexExchangeParam, | ||
DexConfigMap, | ||
} from '../../types'; | ||
import { SwapSide, Network } from '../../constants'; | ||
import { IDexHelper } from '../../dex-helper/idex-helper'; | ||
import { UsualBondData, DexParams } from './types'; | ||
import { Interface, JsonFragment } from '@ethersproject/abi'; | ||
import USD0PP_ABI from '../../abi/usual-bond/usd0pp.abi.json'; | ||
import { Usual } from './usual'; | ||
import { getDexKeysWithNetwork } from '../../utils'; | ||
|
||
const Config: DexConfigMap<DexParams> = { | ||
UsualBond: { | ||
[Network.MAINNET]: { | ||
fromToken: { | ||
address: '0x73a15fed60bf67631dc6cd7bc5b6e8da8190acf5', | ||
decimals: 18, | ||
}, | ||
toToken: { | ||
address: '0x35d8949372d46b7a3d5a56006ae77b215fc69bc0', | ||
decimals: 18, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export class UsualBond extends Usual { | ||
public static dexKeysWithNetwork: { key: string; networks: Network[] }[] = | ||
getDexKeysWithNetwork(Config); | ||
|
||
usd0ppIface: Interface; | ||
|
||
constructor( | ||
readonly network: Network, | ||
readonly dexKey: string, | ||
readonly dexHelper: IDexHelper, | ||
) { | ||
super(network, dexKey, dexHelper, Config[dexKey][network]); | ||
this.usd0ppIface = new Interface(USD0PP_ABI as JsonFragment[]); | ||
} | ||
|
||
async getDexParam( | ||
srcToken: Address, | ||
destToken: Address, | ||
srcAmount: NumberAsString, | ||
destAmount: NumberAsString, | ||
recipient: Address, | ||
data: UsualBondData, | ||
side: SwapSide, | ||
): Promise<DexExchangeParam> { | ||
if (this.isFromToken(srcToken) && this.isToToken(destToken)) { | ||
const exchangeData = this.usd0ppIface.encodeFunctionData('mint', [ | ||
srcAmount, | ||
]); | ||
|
||
return { | ||
needWrapNative: false, | ||
dexFuncHasRecipient: false, | ||
exchangeData, | ||
targetExchange: this.config.toToken.address, | ||
returnAmountPos: undefined, | ||
}; | ||
} | ||
throw new Error('LOGIC ERROR'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* eslint-disable no-console */ | ||
import dotenv from 'dotenv'; | ||
dotenv.config(); | ||
|
||
import { testE2E } from '../../../tests/utils-e2e'; | ||
import { Tokens, Holders } from '../../../tests/constants-e2e'; | ||
import { Network, ContractMethod, SwapSide } from '../../constants'; | ||
import { StaticJsonRpcProvider } from '@ethersproject/providers'; | ||
import { generateConfig } from '../../config'; | ||
|
||
function testForNetwork( | ||
network: Network, | ||
dexKey: string, | ||
tokenASymbol: string, | ||
tokenBSymbol: string, | ||
tokenAAmount: string, | ||
tokenBAmount: string, | ||
) { | ||
const provider = new StaticJsonRpcProvider( | ||
generateConfig(network).privateHttpProvider, | ||
network, | ||
); | ||
const tokens = Tokens[network]; | ||
const holders = Holders[network]; | ||
|
||
const sideToContractMethods = new Map([ | ||
[SwapSide.SELL, [ContractMethod.swapExactAmountIn]], | ||
]); | ||
|
||
describe(`${network}`, () => { | ||
sideToContractMethods.forEach((contractMethods, side) => | ||
describe(`${side}`, () => { | ||
contractMethods.forEach((contractMethod: ContractMethod) => { | ||
describe(`${contractMethod}`, () => { | ||
it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => { | ||
await testE2E( | ||
tokens[tokenASymbol], | ||
tokens[tokenBSymbol], | ||
holders[tokenASymbol], | ||
side === SwapSide.SELL ? tokenAAmount : tokenBAmount, | ||
side, | ||
dexKey, | ||
contractMethod, | ||
network, | ||
provider, | ||
); | ||
}); | ||
}); | ||
}); | ||
}), | ||
); | ||
}); | ||
} | ||
|
||
describe('UsualBond E2E', () => { | ||
const dexKey = 'UsualBond'; | ||
|
||
describe('Mainnet', () => { | ||
const network = Network.MAINNET; | ||
|
||
const tokenASymbol: string = 'USD0'; | ||
const tokenBSymbol: string = 'USD0++'; | ||
|
||
const tokenAAmount: string = '100000'; | ||
const tokenBAmount: string = '100000'; | ||
|
||
testForNetwork( | ||
network, | ||
dexKey, | ||
tokenASymbol, | ||
tokenBSymbol, | ||
tokenAAmount, | ||
tokenBAmount, | ||
); | ||
}); | ||
}); | ||
|
||
describe('UsualMSmartM E2E', () => { | ||
const dexKey = 'UsualMSmartM'; | ||
|
||
describe('Mainnet', () => { | ||
const network = Network.MAINNET; | ||
|
||
const tokenASymbol: string = 'SmartM'; | ||
const tokenBSymbol: string = 'UsualM'; | ||
|
||
const tokenAAmount: string = '100000'; | ||
const tokenBAmount: string = '100000'; | ||
|
||
testForNetwork( | ||
network, | ||
dexKey, | ||
tokenASymbol, | ||
tokenBSymbol, | ||
tokenAAmount, | ||
tokenBAmount, | ||
); | ||
}); | ||
}); | ||
|
||
describe('UsualM<>Usd0 E2E', () => { | ||
const dexKey = 'UsualMUsd0'; | ||
|
||
describe('Mainnet', () => { | ||
const network = Network.MAINNET; | ||
|
||
const tokenASymbol: string = 'UsualM'; | ||
const tokenBSymbol: string = 'USD0'; | ||
|
||
const tokenAAmount: string = '100000'; | ||
const tokenBAmount: string = '100000'; | ||
|
||
testForNetwork( | ||
network, | ||
dexKey, | ||
tokenASymbol, | ||
tokenBSymbol, | ||
tokenAAmount, | ||
tokenBAmount, | ||
); | ||
}); | ||
}); |
Oops, something went wrong.