-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: lending sdk lending protocols config test
- Loading branch information
Showing
8 changed files
with
156 additions
and
7 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,30 @@ | ||
import { ProtocolDataProvider__factory } from './contracts'; | ||
import * as common from '@protocolink/common'; | ||
import { configs } from './configs'; | ||
import { expect } from 'chai'; | ||
|
||
describe('check configs', function () { | ||
for (const { chainId, contractMap, reserves } of configs) { | ||
it(`${common.toNetworkId(chainId)}`, async () => { | ||
const iface = ProtocolDataProvider__factory.createInterface(); | ||
const calls: common.Multicall3.CallStruct[] = reserves.map(({ asset }) => ({ | ||
target: contractMap.ProtocolDataProvider, | ||
callData: iface.encodeFunctionData('getReserveTokensAddresses', [asset.wrapped.address]), | ||
})); | ||
|
||
const web3Toolkit = new common.Web3Toolkit(chainId); | ||
const { returnData } = await web3Toolkit.multicall3.callStatic.aggregate(calls); | ||
for (let i = 0; i < reserves.length; i++) { | ||
const reserve = reserves[i]; | ||
const [aTokenAddress, stableDebtTokenAddress, variableDebtTokenAddress] = iface.decodeFunctionResult( | ||
'getReserveTokensAddresses', | ||
returnData[i] | ||
); | ||
|
||
expect(aTokenAddress).to.eq(reserve.aToken.address); | ||
expect(stableDebtTokenAddress).to.eq(reserve.stableDebtTokenAddress); | ||
expect(variableDebtTokenAddress).to.eq(reserve.variableDebtTokenAddress); | ||
} | ||
}); | ||
} | ||
}); |
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,48 @@ | ||
import { PoolDataProvider__factory } from './contracts'; | ||
import * as common from '@protocolink/common'; | ||
import { configs } from './configs'; | ||
import { expect } from 'chai'; | ||
|
||
describe('check configs', function () { | ||
for (const { chainId, contractMap, reserves } of configs) { | ||
it(`${common.toNetworkId(chainId)}`, async () => { | ||
const iface = PoolDataProvider__factory.createInterface(); | ||
const calls: common.Multicall3.CallStruct[] = []; | ||
for (const { asset } of reserves) { | ||
calls.push({ | ||
target: contractMap.PoolDataProvider, | ||
callData: iface.encodeFunctionData('getReserveTokensAddresses', [asset.wrapped.address]), | ||
}); | ||
if (!asset.isNative) { | ||
calls.push({ | ||
target: contractMap.PoolDataProvider, | ||
callData: iface.encodeFunctionData('getFlashLoanEnabled', [asset.address]), | ||
}); | ||
} | ||
} | ||
|
||
const web3Toolkit = new common.Web3Toolkit(chainId); | ||
const { returnData } = await web3Toolkit.multicall3.callStatic.aggregate(calls); | ||
|
||
let j = 0; | ||
for (const reserve of reserves) { | ||
const [aTokenAddress, stableDebtTokenAddress, variableDebtTokenAddress] = iface.decodeFunctionResult( | ||
'getReserveTokensAddresses', | ||
returnData[j] | ||
); | ||
expect(aTokenAddress).to.eq(reserve.aToken.address); | ||
expect(stableDebtTokenAddress).to.eq(reserve.stableDebtTokenAddress); | ||
expect(variableDebtTokenAddress).to.eq(reserve.variableDebtTokenAddress); | ||
j++; | ||
|
||
if (!reserve.asset.isNative) { | ||
const [flashLoanEnabled] = iface.decodeFunctionResult('getFlashLoanEnabled', returnData[j]); | ||
if (flashLoanEnabled) { | ||
expect(reserve.used.flashLoan).to.be.true; | ||
} | ||
j++; | ||
} | ||
} | ||
}); | ||
} | ||
}); |
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
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,34 @@ | ||
import { Comet__factory } from './contracts'; | ||
import * as common from '@protocolink/common'; | ||
import { configs } from './configs'; | ||
import { expect } from 'chai'; | ||
|
||
describe('check configs', function () { | ||
for (const { chainId, markets } of configs) { | ||
for (const market of markets) { | ||
it(`${common.toNetworkId(chainId)}: ${market.baseToken.symbol}`, async () => { | ||
const iface = Comet__factory.createInterface(); | ||
const web3Toolkit = new common.Web3Toolkit(chainId); | ||
|
||
const calls: common.Multicall3.CallStruct[] = [ | ||
{ | ||
target: market.cometAddress, | ||
callData: iface.encodeFunctionData('baseToken'), | ||
}, | ||
{ | ||
target: market.cometAddress, | ||
callData: iface.encodeFunctionData('baseTokenPriceFeed'), | ||
}, | ||
]; | ||
|
||
const { returnData } = await web3Toolkit.multicall3.callStatic.aggregate(calls); | ||
|
||
const [baseTokenAddress] = iface.decodeFunctionResult('baseToken', returnData[0]); | ||
expect(baseTokenAddress).to.eq(market.baseToken.address); | ||
|
||
const [baseTokenPriceFeedAddress] = iface.decodeFunctionResult('baseTokenPriceFeed', returnData[1]); | ||
expect(baseTokenPriceFeedAddress).to.eq(market.baseTokenPriceFeedAddress); | ||
}); | ||
} | ||
} | ||
}); |
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,29 @@ | ||
import { ProtocolDataProvider__factory } from './contracts'; | ||
import * as common from '@protocolink/common'; | ||
import { configs } from './configs'; | ||
import { expect } from 'chai'; | ||
|
||
describe('check configs', function () { | ||
for (const { chainId, contractMap, reserves } of configs) { | ||
it(`${common.toNetworkId(chainId)}`, async () => { | ||
const iface = ProtocolDataProvider__factory.createInterface(); | ||
const calls: common.Multicall3.CallStruct[] = reserves.map(({ asset }) => ({ | ||
target: contractMap.ProtocolDataProvider, | ||
callData: iface.encodeFunctionData('getReserveTokensAddresses', [asset.wrapped.address]), | ||
})); | ||
|
||
const web3Toolkit = new common.Web3Toolkit(chainId); | ||
const { returnData } = await web3Toolkit.multicall3.callStatic.aggregate(calls); | ||
for (let i = 0; i < reserves.length; i++) { | ||
const reserve = reserves[i]; | ||
const { rTokenAddress, variableDebtTokenAddress } = iface.decodeFunctionResult( | ||
'getReserveTokensAddresses', | ||
returnData[i] | ||
); | ||
|
||
expect(rTokenAddress).to.eq(reserve.rToken.address); | ||
expect(variableDebtTokenAddress).to.eq(reserve.variableDebtTokenAddress); | ||
} | ||
}); | ||
} | ||
}); |