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

fix: provider passing in options #4731

Merged
merged 8 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
32 changes: 32 additions & 0 deletions packages/agents/sdk-wrapper/src/sdkPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ export class SdkPool extends SdkShared {
): Promise<BigNumber> {
const _options = options ?? {
chains: this.config.chains,
originProviderUrl: this.config.chains[domainId]?.providers?.[0],
just-a-node marked this conversation as resolved.
Show resolved Hide resolved
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
tokenAddress,
Expand Down Expand Up @@ -179,8 +181,10 @@ export class SdkPool extends SdkShared {
): Promise<BigNumber> {
const _options = options ?? {
chains: this.config.chains,
originProviderUrl: this.config.chains[domainId]?.providers?.[0],
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
tokenAddress,
Expand All @@ -201,8 +205,10 @@ export class SdkPool extends SdkShared {
): Promise<BigNumber[]> {
const _options = options ?? {
chains: this.config.chains,
originProviderUrl: this.config.chains[domainId]?.providers?.[0],
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
tokenAddress,
Expand All @@ -223,8 +229,10 @@ export class SdkPool extends SdkShared {
): Promise<BigNumber> {
const _options = options ?? {
chains: this.config.chains,
originProviderUrl: this.config.chains[domainId]?.providers?.[0],
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
tokenAddress,
Expand Down Expand Up @@ -262,7 +270,14 @@ export class SdkPool extends SdkShared {
tokenAddress: string,
amountX: string,
amountY: string,
options?: Options,
): Promise<BigNumber | undefined> {
const _options = options ?? {
chains: this.config.chains,
originProviderUrl: this.config.chains[domainId]?.providers?.[0],
signerAddress: this.config.signerAddress,
};

const params: { domainId: string; tokenAddress: string; amountX: string; amountY: string } = {
domainId,
tokenAddress,
Expand All @@ -279,7 +294,14 @@ export class SdkPool extends SdkShared {
tokenAddress: string,
amountX: string,
amountY: string,
options?: Options,
): Promise<BigNumber | undefined> {
const _options = options ?? {
chains: this.config.chains,
originProviderUrl: this.config.chains[domainId]?.providers?.[0],
signerAddress: this.config.signerAddress,
};

const params: { domainId: string; tokenAddress: string; amountX: string; amountY: string } = {
domainId,
tokenAddress,
Expand All @@ -300,8 +322,10 @@ export class SdkPool extends SdkShared {
): Promise<BigNumber> {
const _options = options ?? {
chains: this.config.chains,
originProviderUrl: this.config.chains[domainId]?.providers?.[0],
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
amountX,
Expand Down Expand Up @@ -398,8 +422,10 @@ export class SdkPool extends SdkShared {
): Promise<BigNumber> {
const _options = options ?? {
chains: this.config.chains,
originProviderUrl: this.config.chains[domainId]?.providers?.[0],
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
tokenAddress,
Expand All @@ -425,8 +451,10 @@ export class SdkPool extends SdkShared {
async getVirtualPrice(domainId: string, tokenAddress: string, options?: Options): Promise<BigNumber> {
const _options = options ?? {
chains: this.config.chains,
originProviderUrl: this.config.chains[domainId]?.providers?.[0],
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
tokenAddress,
Expand Down Expand Up @@ -556,8 +584,10 @@ export class SdkPool extends SdkShared {
): Promise<providers.TransactionRequest> {
const _options = options ?? {
chains: this.config.chains,
originProviderUrl: this.config.chains[domainId]?.providers?.[0],
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
tokenAddress,
Expand All @@ -582,8 +612,10 @@ export class SdkPool extends SdkShared {
): Promise<providers.TransactionRequest> {
const _options = options ?? {
chains: this.config.chains,
originProviderUrl: this.config.chains[domainId]?.providers?.[0],
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
tokenAddress,
Expand Down
2 changes: 2 additions & 0 deletions packages/agents/sdk-wrapper/src/sdkShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ export class SdkShared {
): Promise<providers.TransactionRequest | undefined> {
const _options = options ?? {
chains: this.config.chains,
originProviderUrl: this.config.chains[domainId]?.providers?.[0],
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
assetId,
Expand Down
9 changes: 9 additions & 0 deletions packages/agents/sdk-wrapper/test/sdkPool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ describe("#SDKPool", () => {
options: {
chains: mockConfig.chains,
signerAddress: mockConfig.signerAddress,
originProviderUrl: mockConfig.chains[mockXTransfer.xparams.originDomain].providers?.[0],
},
};
const mockServerRes = {
Expand Down Expand Up @@ -376,6 +377,7 @@ describe("#SDKPool", () => {
options: {
chains: mockConfig.chains,
signerAddress: mockConfig.signerAddress,
originProviderUrl: mockConfig.chains[mockXTransfer.xparams.originDomain].providers?.[0],
},
};
const mockServerRes = {
Expand Down Expand Up @@ -453,6 +455,7 @@ describe("#SDKPool", () => {
options: {
chains: mockConfig.chains,
signerAddress: mockConfig.signerAddress,
originProviderUrl: mockConfig.chains[mockXTransfer.xparams.originDomain].providers?.[0],
},
};
const mockServerRes = [
Expand Down Expand Up @@ -540,6 +543,7 @@ describe("#SDKPool", () => {
options: {
chains: mockConfig.chains,
signerAddress: mockConfig.signerAddress,
originProviderUrl: mockConfig.chains[mockXTransfer.xparams.originDomain].providers?.[0],
},
};
const mockServerRes = {
Expand Down Expand Up @@ -692,6 +696,7 @@ describe("#SDKPool", () => {
options: {
chains: mockConfig.chains,
signerAddress: mockConfig.signerAddress,
originProviderUrl: mockConfig.chains[mockXTransfer.xparams.originDomain].providers?.[0],
},
};
const mockServerRes = {
Expand Down Expand Up @@ -1002,6 +1007,7 @@ describe("#SDKPool", () => {
options: {
chains: mockConfig.chains,
signerAddress: mockConfig.signerAddress,
originProviderUrl: mockConfig.chains[mockXTransfer.xparams.originDomain].providers?.[0],
},
};
const mockServerRes = {
Expand Down Expand Up @@ -1104,6 +1110,7 @@ describe("#SDKPool", () => {
options: {
chains: mockConfig.chains,
signerAddress: mockConfig.signerAddress,
originProviderUrl: mockConfig.chains[mockXTransfer.xparams.originDomain].providers?.[0],
},
};
const mockServerRes = {
Expand Down Expand Up @@ -1468,6 +1475,7 @@ describe("#SDKPool", () => {
options: {
chains: mockConfig.chains,
signerAddress: mockConfig.signerAddress,
originProviderUrl: mockConfig.chains[mockXTransfer.xparams.originDomain].providers?.[0],
},
};

Expand Down Expand Up @@ -1542,6 +1550,7 @@ describe("#SDKPool", () => {
options: {
chains: mockConfig.chains,
signerAddress: mockConfig.signerAddress,
originProviderUrl: mockConfig.chains[mockXTransfer.xparams.originDomain].providers?.[0],
},
};

Expand Down
3 changes: 2 additions & 1 deletion packages/agents/sdk-wrapper/test/sdkShared.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe("#SDKShared", () => {
status: 200,
});

const res = await sdkShared.getDeploymentAddress(expectedArgs.domainId, expectedArgs.deploymentName);
const res = await sdkShared.getDeploymentAddress(expectedArgs.domainId, expectedArgs.deploymentName as "connext");

expect(axiosGetStub).to.have.been.calledWithExactly(
expectedBaseUri + expectedEndpoint + `/${expectedArgs.domainId}` + `/${expectedArgs.deploymentName}`,
Expand Down Expand Up @@ -334,6 +334,7 @@ describe("#SDKShared", () => {
options: {
chains: mockConfig.chains,
signerAddress: mockConfig.signerAddress,
originProviderUrl: mockConfig.chains[mock.domain.A].providers?.[0],
},
};

Expand Down
2 changes: 2 additions & 0 deletions packages/agents/sdk/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ export const SdkCalculateAddLiquidityPriceImpactParamsSchema = Type.Object({
tokenAddress: Type.String(),
amountX: Type.String(),
amountY: Type.String(),
options: Type.Optional(OptionsSchema),
});
export type SdkCalculateAddLiquidityPriceImpactParams = Static<typeof SdkCalculateAddLiquidityPriceImpactParamsSchema>;

Expand All @@ -520,6 +521,7 @@ export const SdkCalculateRemoveLiquidityPriceImpactParamsSchema = Type.Object({
tokenAddress: Type.String(),
amountX: Type.String(),
amountY: Type.String(),
options: Type.Optional(OptionsSchema),
});
export type SdkCalculateRemoveLiquidityPriceImpactParams = Static<
typeof SdkCalculateRemoveLiquidityPriceImpactParamsSchema
Expand Down
10 changes: 7 additions & 3 deletions packages/agents/sdk/src/sdkPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,12 @@ export class SdkPool extends SdkShared {
tokenAddress: string,
amountX: string,
amountY: string,
options?: Options,
): Promise<BigNumber | undefined> {
const _tokenAddress = utils.getAddress(tokenAddress);

const [virtualPrice, lpTokenAmount] = await Promise.all([
this.getVirtualPrice(domainId, _tokenAddress),
this.getVirtualPrice(domainId, _tokenAddress, options),
this.calculateTokenAmount(domainId, _tokenAddress, [amountX, amountY]),
]);

Expand Down Expand Up @@ -518,12 +519,13 @@ export class SdkPool extends SdkShared {
tokenAddress: string,
amountX: string,
amountY: string,
options?: Options,
): Promise<BigNumber | undefined> {
const _tokenAddress = utils.getAddress(tokenAddress);

const [virtualPrice, lpTokenAmount] = await Promise.all([
this.getVirtualPrice(domainId, _tokenAddress),
this.calculateTokenAmount(domainId, _tokenAddress, [amountX, amountY], false),
this.calculateTokenAmount(domainId, _tokenAddress, [amountX, amountY], false, options),
]);

// Normalize to 18 decimals
Expand Down Expand Up @@ -1133,7 +1135,9 @@ export class SdkPool extends SdkShared {
this.logger.debug(`No Pool for token ${_tokenAddress} on domain ${domainId}`);
}
const poolData = poolDataResults[0]; // there should only be one pool
maxBurnAmount = (await this.getTokenUserBalance(domainId, String(poolData.lp_token), _signerAddress)).toString();
maxBurnAmount = (
await this.getTokenUserBalance(domainId, String(poolData.lp_token), _signerAddress, options)
).toString();
}

const txRequest = await connextContract.populateTransaction.removeSwapLiquidityImbalance(
Expand Down