Skip to content

Commit

Permalink
DCA client fix (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan authored Sep 27, 2022
1 parent 7459813 commit 87d962f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aztec/bridge-clients",
"version": "0.1.58",
"version": "0.1.59",
"description": "This repo contains the solidity files and typescript helper class for all of the Aztec Connect Bridge Contracts",
"repository": "[email protected]:AztecProtocol/aztec-connect-bridges.git",
"license": "Apache-2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DCABridgeData } from "./dca";
import { BiDCABridge, BiDCABridge__factory, IERC20__factory } from "../../../typechain-types";
import { DCABridgeData } from "./dca-bridge-data";
import { BiDCABridge, BiDCABridge__factory } from "../../../typechain-types";
import { AztecAsset, AztecAssetType } from "../bridge-data";
import { BigNumber } from "ethers";
import { EthAddress } from "@aztec/barretenberg/address";
Expand Down Expand Up @@ -123,15 +123,18 @@ describe("DCA bridge data", () => {
};

dcaBridgeData = createDCABridge(dcaBridgeContract as any);
const res = await dcaBridgeData.getInteractionPresentValue(0);

// User owned half the batch
const inputValue = dcas[0].amount.toBigInt() / 2n;
const res = await dcaBridgeData.getInteractionPresentValue(0, inputValue);

expect(res[0]).toEqual({
assetId: 1,
value: (55n * 10n ** 18n) / 10n,
value: (55n * 10n ** 18n) / 10n / 2n,
});
expect(res[1]).toEqual({
assetId: 0,
value: (15n * 10n ** 18n) / 10000n,
value: (15n * 10n ** 18n) / 10000n / 2n,
});
});

Expand Down
17 changes: 4 additions & 13 deletions src/client/dca/dca.ts → src/client/dca/dca-bridge-data.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
UnderlyingAsset,
AuxDataConfig,
AztecAsset,
SolidityType,
AztecAssetType,
BridgeDataFieldGetters,
} from "../bridge-data";
import { UnderlyingAsset, AuxDataConfig, AztecAsset, SolidityType, BridgeDataFieldGetters } from "../bridge-data";

import { BiDCABridge, BiDCABridge__factory, IERC20__factory } from "../../../typechain-types";
import { EthereumProvider } from "@aztec/barretenberg/blockchain";
Expand All @@ -25,7 +18,6 @@ export class DCABridgeData implements BridgeDataFieldGetters {
return new DCABridgeData(bidcaContract);
}

// Unused
public auxDataConfig: AuxDataConfig[] = [
{
start: 0,
Expand All @@ -35,8 +27,7 @@ export class DCABridgeData implements BridgeDataFieldGetters {
},
];

// Lido bridge contract is stateless
async getInteractionPresentValue(interactionNonce: number): Promise<AssetValue[]> {
async getInteractionPresentValue(interactionNonce: number, inputValue: bigint): Promise<AssetValue[]> {
const position = await this.bidcaContract.getDCA(interactionNonce);

const tickAmount = position.amount.div(position.end - position.start);
Expand Down Expand Up @@ -65,11 +56,11 @@ export class DCABridgeData implements BridgeDataFieldGetters {
return [
{
assetId: aToB ? 1 : 0,
value: position.amount.toBigInt() - soldSum,
value: ((position.amount.toBigInt() - soldSum) * inputValue) / position.amount.toBigInt(),
},
{
assetId: !aToB ? 1 : 0,
value: boughtSum,
value: (boughtSum * inputValue) / position.amount.toBigInt(),
},
];
}
Expand Down

0 comments on commit 87d962f

Please sign in to comment.