Skip to content

Commit

Permalink
Feature/get denormalized weight #26 (#35)
Browse files Browse the repository at this point in the history
* rebase

* fix conflicts

* moves mainnet test
  • Loading branch information
travisdmathis authored Jun 8, 2020
1 parent 0ebd33a commit 071fcbd
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ artifacts
.DS_Store
coverage.json
flats.sol
.coverage_cache/
.coverage_contracts/
8 changes: 8 additions & 0 deletions contracts/smart-pools/PBasicSmartPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ contract PBasicSmartPool is IPSmartPool, PCToken, ReentryProtection {
return address(lpbs().bPool);
}

/**
@notice Get the denormalized weight of a specific token in the underlying balancer pool
@return the normalized weight of the token in uint
*/
function getDenormalizedWeight(address _token) external view returns (uint256) {
return lpbs().bPool.getDenormalizedWeight(_token);
}

/**
@notice Pull the underlying token from an address and rebind it to the balancer pool
@param _token Address of the token to pull
Expand Down
6 changes: 6 additions & 0 deletions mainnet-test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ describe("MAINNET TEST", function () {
expect(poolTokens[poolTokens.length - 1]).to.eq(mockToken.address);
});

it("Gets denormalized weight of underlying token in balancer pool", async () => {
const tokenWeight = await pool.getDenormalizedWeight(mockToken.address);

expect(tokenWeight).to.eq(constants.WeiPerEther);
});

it("Unbinding a token should work", async () => {
await (await pool.unbind(mockToken.address, {gasLimit: 2000000})).wait(1);
const poolTokens = await bPool.getCurrentTokens();
Expand Down
12 changes: 12 additions & 0 deletions test/pBasicSmartPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,18 @@ describe("PBasicSmartPool", function () {
});
});

describe("Utility Functions", async () => {
describe("getDenormalizedWeight(address _token)", async () => {
it("Should return denormalized weight of underlying token in bPool", async () => {
smartpool = smartpool.connect(signers[1]);

const tokenWeight = await smartpool.getDenormalizedWeight(tokens[0].address);

expect(tokenWeight).to.equal(constants.WeiPerEther);
});
});
});

async function getTokenBalances(address: string) {
const balances: BigNumber[] = [];

Expand Down
2 changes: 1 addition & 1 deletion typechain/OwnableFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ const _abi = [
];

const _bytecode =
"0x608060405234801561001057600080fd5b50610207806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063f09078431461003b578063f2fde38b14610055575b600080fd5b61004361007d565b60408051918252519081900360200190f35b61007b6004803603602081101561006b57600080fd5b50356001600160a01b03166100ad565b005b604080517727bbb730b136329739ba37b930b3b2973637b1b0ba34b7b760411b8152905190819003601801902081565b6100b5610108565b546001600160a01b031633146100fc5760405162461bcd60e51b81526004018080602001828103825260278152602001806101ab6027913960400191505060405180910390fd5b61010581610138565b50565b604080517727bbb730b136329739ba37b930b3b2973637b1b0ba34b7b760411b8152905190819003601801902090565b806001600160a01b031661014a610108565b546040516001600160a01b03909116907fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c90600090a380610189610108565b80546001600160a01b0319166001600160a01b03929092169190911790555056fe4f776e61626c652e6f6e6c794f776e65723a206d73672e73656e646572206e6f74206f776e6572a2646970667358221220144844ab9efc7c74e6d35dce1d5b08cb033ec65c32018f0cf3f2df59e5db7af064736f6c63430006040033";
"0x608060405234801561001057600080fd5b50610207806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063f09078431461003b578063f2fde38b14610055575b600080fd5b61004361007d565b60408051918252519081900360200190f35b61007b6004803603602081101561006b57600080fd5b50356001600160a01b03166100ad565b005b604080517727bbb730b136329739ba37b930b3b2973637b1b0ba34b7b760411b8152905190819003601801902081565b6100b5610108565b546001600160a01b031633146100fc5760405162461bcd60e51b81526004018080602001828103825260278152602001806101ab6027913960400191505060405180910390fd5b61010581610138565b50565b604080517727bbb730b136329739ba37b930b3b2973637b1b0ba34b7b760411b8152905190819003601801902090565b806001600160a01b031661014a610108565b546040516001600160a01b03909116907fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c90600090a380610189610108565b80546001600160a01b0319166001600160a01b03929092169190911790555056fe4f776e61626c652e6f6e6c794f776e65723a206d73672e73656e646572206e6f74206f776e6572a2646970667358221220fd47057d206a73520b2606dab719cee4d50e17c7273a648b985aaed7e1e820d164736f6c63430006040033";
10 changes: 10 additions & 0 deletions typechain/PBasicSmartPool.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ interface PBasicSmartPoolInterface extends Interface {

getController: TypedFunctionDescription<{ encode([]: []): string }>;

getDenormalizedWeight: TypedFunctionDescription<{
encode([_token]: [string]): string;
}>;

getPublicSwapSetter: TypedFunctionDescription<{ encode([]: []): string }>;

getSwapFee: TypedFunctionDescription<{ encode([]: []): string }>;
Expand Down Expand Up @@ -284,6 +288,8 @@ export class PBasicSmartPool extends Contract {

getController(): Promise<string>;

getDenormalizedWeight(_token: string): Promise<BigNumber>;

getPublicSwapSetter(): Promise<string>;

getSwapFee(): Promise<BigNumber>;
Expand Down Expand Up @@ -427,6 +433,8 @@ export class PBasicSmartPool extends Contract {

getController(): Promise<string>;

getDenormalizedWeight(_token: string): Promise<BigNumber>;

getPublicSwapSetter(): Promise<string>;

getSwapFee(): Promise<BigNumber>;
Expand Down Expand Up @@ -607,6 +615,8 @@ export class PBasicSmartPool extends Contract {

getController(): Promise<BigNumber>;

getDenormalizedWeight(_token: string): Promise<BigNumber>;

getPublicSwapSetter(): Promise<BigNumber>;

getSwapFee(): Promise<BigNumber>;
Expand Down
21 changes: 20 additions & 1 deletion typechain/PBasicSmartPoolFactory.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion typechain/PCTokenFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,4 @@ const _abi = [
];

const _bytecode =
"0x608060405234801561001057600080fd5b50610a8c806100206000396000f3fe608060405234801561001057600080fd5b50600436106100b45760003560e01c806370a082311161007157806370a082311461021057806395d89b4114610236578063a9059cbb1461023e578063d73dd6231461026a578063dd62ed3e14610296578063ec565ffe146102c4576100b4565b806306fdde03146100b9578063095ea7b31461013657806318160ddd1461017657806323b872dd14610190578063313ce567146101c657806366188463146101e4575b600080fd5b6100c16102cc565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100fb5781810151838201526020016100e3565b50505050905090810190601f1680156101285780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101626004803603604081101561014c57600080fd5b506001600160a01b038135169060200135610364565b604080519115158252519081900360200190f35b61017e6103c9565b60408051918252519081900360200190f35b610162600480360360608110156101a657600080fd5b506001600160a01b038135811691602081013590911690604001356103dc565b6101ce610551565b6040805160ff9092168252519081900360200190f35b610162600480360360408110156101fa57600080fd5b506001600160a01b038135169060200135610556565b61017e6004803603602081101561022657600080fd5b50356001600160a01b031661064b565b6100c1610677565b6101626004803603604081101561025457600080fd5b506001600160a01b0381351690602001356106dd565b6101626004803603604081101561028057600080fd5b506001600160a01b0381351690602001356106f3565b61017e600480360360408110156102ac57600080fd5b506001600160a01b038135811691602001351661078d565b61017e6107c7565b60606102d66107f7565b805460408051602060026001851615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561035a5780601f1061032f5761010080835404028352916020019161035a565b820191906000526020600020905b81548152906001019060200180831161033d57829003601f168201915b5050505050905090565b60008161036f6107f7565b336000818152600492909201602090815260408084206001600160a01b03891680865290835293819020949094558351868152935192939192600080516020610a378339815191529281900390910190a350600192915050565b60006103d36107f7565b60020154905090565b6000806103e76107f7565b9050336001600160a01b038616148061042557506001600160a01b038516600090815260048201602090815260408083203384529091529020548311155b61046f576040805162461bcd60e51b815260206004820152601660248201527522a9292fa821aa27a5a2a72fa120a22fa1a0a62622a960511b604482015290519081900360640190fd5b61047a858585610827565b336001600160a01b038616148015906104ba57506001600160a01b0385166000908152600482016020908152604080832033845290915290205460001914155b15610546576001600160a01b038516600090815260048201602090815260408083203384529091529020546104f5908463ffffffff61095b16565b6001600160a01b03868116600090815260048401602090815260408083203380855290835292819020859055805194855251928816939192600080516020610a378339815191529281900390910190a35b506001949350505050565b601281565b6000806105616107f7565b33600090815260048201602090815260408083206001600160a01b0389168452909152902054909150808411156105bd5733600090815260048301602090815260408083206001600160a01b03891684529091528120556105f4565b6105cd818563ffffffff61095b16565b33600090815260048401602090815260408083206001600160a01b038a1684529091529020555b33600081815260048401602090815260408083206001600160a01b038a16808552908352928190205481519081529051929392600080516020610a37833981519152929181900390910190a3506001949350505050565b60006106556107f7565b6001600160a01b03929092166000908152600390920160205250604090205490565b60606106816107f7565b60019081018054604080516020600295841615610100026000190190931694909404601f81018390048302850183019091528084529083018282801561035a5780601f1061032f5761010080835404028352916020019161035a565b60006106ea338484610827565b50600192915050565b6000806106fe6107f7565b33600090815260048201602090815260408083206001600160a01b0389168452909152902054909150610737908463ffffffff6109bd16565b33600081815260048401602090815260408083206001600160a01b038a16808552908352928190208590558051948552519193600080516020610a37833981519152929081900390910190a35060019392505050565b60006107976107f7565b6001600160a01b039384166000908152600491909101602090815260408083209490951682529290925250205490565b60408051772821aa37b5b2b71739ba37b930b3b2973637b1b0ba34b7b760411b8152905190819003601801902081565b60408051772821aa37b5b2b71739ba37b930b3b2973637b1b0ba34b7b760411b8152905190819003601801902090565b60006108316107f7565b6001600160a01b038516600090815260038201602052604090205490915082111561089a576040805162461bcd60e51b815260206004820152601460248201527311549497d25394d551919250d251539517d0905360621b604482015290519081900360640190fd5b6001600160a01b03841660009081526003820160205260409020546108c5908363ffffffff61095b16565b6001600160a01b03808616600090815260038401602052604080822093909355908516815220546108fc908363ffffffff6109bd16565b6001600160a01b03808516600081815260038501602090815260409182902094909455805186815290519193928816927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a350505050565b600080600061096a8585610a11565b9150915080156109b5576040805162461bcd60e51b81526020600482015260116024820152704552525f5355425f554e444552464c4f5760781b604482015290519081900360640190fd5b509392505050565b600082820183811015610a0a576040805162461bcd60e51b815260206004820152601060248201526f4552525f4144445f4f564552464c4f5760801b604482015290519081900360640190fd5b9392505050565b600080828410610a275750508082036000610a2f565b505081810360015b925092905056fe8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a2646970667358221220fa1e36212bbf4e6bbacc6527dcd85438e55f3bbe1a156a8c8361d69ce89eb7c464736f6c63430006040033";
"0x608060405234801561001057600080fd5b50610a8c806100206000396000f3fe608060405234801561001057600080fd5b50600436106100b45760003560e01c806370a082311161007157806370a082311461021057806395d89b4114610236578063a9059cbb1461023e578063d73dd6231461026a578063dd62ed3e14610296578063ec565ffe146102c4576100b4565b806306fdde03146100b9578063095ea7b31461013657806318160ddd1461017657806323b872dd14610190578063313ce567146101c657806366188463146101e4575b600080fd5b6100c16102cc565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100fb5781810151838201526020016100e3565b50505050905090810190601f1680156101285780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101626004803603604081101561014c57600080fd5b506001600160a01b038135169060200135610364565b604080519115158252519081900360200190f35b61017e6103c9565b60408051918252519081900360200190f35b610162600480360360608110156101a657600080fd5b506001600160a01b038135811691602081013590911690604001356103dc565b6101ce610551565b6040805160ff9092168252519081900360200190f35b610162600480360360408110156101fa57600080fd5b506001600160a01b038135169060200135610556565b61017e6004803603602081101561022657600080fd5b50356001600160a01b031661064b565b6100c1610677565b6101626004803603604081101561025457600080fd5b506001600160a01b0381351690602001356106dd565b6101626004803603604081101561028057600080fd5b506001600160a01b0381351690602001356106f3565b61017e600480360360408110156102ac57600080fd5b506001600160a01b038135811691602001351661078d565b61017e6107c7565b60606102d66107f7565b805460408051602060026001851615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561035a5780601f1061032f5761010080835404028352916020019161035a565b820191906000526020600020905b81548152906001019060200180831161033d57829003601f168201915b5050505050905090565b60008161036f6107f7565b336000818152600492909201602090815260408084206001600160a01b03891680865290835293819020949094558351868152935192939192600080516020610a378339815191529281900390910190a350600192915050565b60006103d36107f7565b60020154905090565b6000806103e76107f7565b9050336001600160a01b038616148061042557506001600160a01b038516600090815260048201602090815260408083203384529091529020548311155b61046f576040805162461bcd60e51b815260206004820152601660248201527522a9292fa821aa27a5a2a72fa120a22fa1a0a62622a960511b604482015290519081900360640190fd5b61047a858585610827565b336001600160a01b038616148015906104ba57506001600160a01b0385166000908152600482016020908152604080832033845290915290205460001914155b15610546576001600160a01b038516600090815260048201602090815260408083203384529091529020546104f5908463ffffffff61095b16565b6001600160a01b03868116600090815260048401602090815260408083203380855290835292819020859055805194855251928816939192600080516020610a378339815191529281900390910190a35b506001949350505050565b601281565b6000806105616107f7565b33600090815260048201602090815260408083206001600160a01b0389168452909152902054909150808411156105bd5733600090815260048301602090815260408083206001600160a01b03891684529091528120556105f4565b6105cd818563ffffffff61095b16565b33600090815260048401602090815260408083206001600160a01b038a1684529091529020555b33600081815260048401602090815260408083206001600160a01b038a16808552908352928190205481519081529051929392600080516020610a37833981519152929181900390910190a3506001949350505050565b60006106556107f7565b6001600160a01b03929092166000908152600390920160205250604090205490565b60606106816107f7565b60019081018054604080516020600295841615610100026000190190931694909404601f81018390048302850183019091528084529083018282801561035a5780601f1061032f5761010080835404028352916020019161035a565b60006106ea338484610827565b50600192915050565b6000806106fe6107f7565b33600090815260048201602090815260408083206001600160a01b0389168452909152902054909150610737908463ffffffff6109bd16565b33600081815260048401602090815260408083206001600160a01b038a16808552908352928190208590558051948552519193600080516020610a37833981519152929081900390910190a35060019392505050565b60006107976107f7565b6001600160a01b039384166000908152600491909101602090815260408083209490951682529290925250205490565b60408051772821aa37b5b2b71739ba37b930b3b2973637b1b0ba34b7b760411b8152905190819003601801902081565b60408051772821aa37b5b2b71739ba37b930b3b2973637b1b0ba34b7b760411b8152905190819003601801902090565b60006108316107f7565b6001600160a01b038516600090815260038201602052604090205490915082111561089a576040805162461bcd60e51b815260206004820152601460248201527311549497d25394d551919250d251539517d0905360621b604482015290519081900360640190fd5b6001600160a01b03841660009081526003820160205260409020546108c5908363ffffffff61095b16565b6001600160a01b03808616600090815260038401602052604080822093909355908516815220546108fc908363ffffffff6109bd16565b6001600160a01b03808516600081815260038501602090815260409182902094909455805186815290519193928816927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a350505050565b600080600061096a8585610a11565b9150915080156109b5576040805162461bcd60e51b81526020600482015260116024820152704552525f5355425f554e444552464c4f5760781b604482015290519081900360640190fd5b509392505050565b600082820183811015610a0a576040805162461bcd60e51b815260206004820152601060248201526f4552525f4144445f4f564552464c4f5760801b604482015290519081900360640190fd5b9392505050565b600080828410610a275750508082036000610a2f565b505081810360015b925092905056fe8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a264697066735822122048a15fde584a124d68a634327fdef9a480f866f44f5fae10517e921b06fffbfc64736f6c63430006040033";
2 changes: 1 addition & 1 deletion typechain/PCTokenStorageFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ const _abi = [
];

const _bytecode =
"0x6080604052348015600f57600080fd5b5060b08061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063ec565ffe14602d575b600080fd5b60336045565b60408051918252519081900360200190f35b604080517f5043546f6b656e2e73746f726167652e6c6f636174696f6e0000000000000000815290519081900360180190208156fea2646970667358221220df79c5e43cd826dfb4261668ab3b7cac53111315566bcf1f1f6b026553eaf37564736f6c63430006040033";
"0x6080604052348015600f57600080fd5b5060b08061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063ec565ffe14602d575b600080fd5b60336045565b60408051918252519081900360200190f35b604080517f5043546f6b656e2e73746f726167652e6c6f636174696f6e0000000000000000815290519081900360180190208156fea26469706673582212201e917d32380c93a7117e5d19b7164b24ca05575f907a312f6a6407ab8bac4bfd64736f6c63430006040033";
10 changes: 10 additions & 0 deletions typechain/PCappedSmartPool.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ interface PCappedSmartPoolInterface extends Interface {

getController: TypedFunctionDescription<{ encode([]: []): string }>;

getDenormalizedWeight: TypedFunctionDescription<{
encode([_token]: [string]): string;
}>;

getPublicSwapSetter: TypedFunctionDescription<{ encode([]: []): string }>;

getSwapFee: TypedFunctionDescription<{ encode([]: []): string }>;
Expand Down Expand Up @@ -302,6 +306,8 @@ export class PCappedSmartPool extends Contract {

getController(): Promise<string>;

getDenormalizedWeight(_token: string): Promise<BigNumber>;

getPublicSwapSetter(): Promise<string>;

getSwapFee(): Promise<BigNumber>;
Expand Down Expand Up @@ -454,6 +460,8 @@ export class PCappedSmartPool extends Contract {

getController(): Promise<string>;

getDenormalizedWeight(_token: string): Promise<BigNumber>;

getPublicSwapSetter(): Promise<string>;

getSwapFee(): Promise<BigNumber>;
Expand Down Expand Up @@ -645,6 +653,8 @@ export class PCappedSmartPool extends Contract {

getController(): Promise<BigNumber>;

getDenormalizedWeight(_token: string): Promise<BigNumber>;

getPublicSwapSetter(): Promise<BigNumber>;

getSwapFee(): Promise<BigNumber>;
Expand Down
21 changes: 20 additions & 1 deletion typechain/PCappedSmartPoolFactory.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion typechain/PProxiedFactoryFactory.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion typechain/ReentryProtectionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ const _abi = [
];

const _bytecode =
"0x6080604052348015600f57600080fd5b5060b78061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063830df85214602d575b600080fd5b60336045565b60408051918252519081900360200190f35b60405180602260608239602201905060405180910390208156fe5265656e74727950726f74656374696f6e2e73746f726167652e6c6f636174696f6ea26469706673582212203f784987443785016d9460a6a4960600880de49d6dd2fc5d318c357a1e2f2b5464736f6c63430006040033";
"0x6080604052348015600f57600080fd5b5060b78061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063830df85214602d575b600080fd5b60336045565b60408051918252519081900360200190f35b60405180602260608239602201905060405180910390208156fe5265656e74727950726f74656374696f6e2e73746f726167652e6c6f636174696f6ea26469706673582212207d1eeea7dac483405e2e101cc99b76635591094e5498ffedddc66724a9f2fedc64736f6c63430006040033";
Loading

0 comments on commit 071fcbd

Please sign in to comment.