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 all 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
4 changes: 4 additions & 0 deletions packages/agents/sdk-wrapper/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Next Release

## v2.1.2

- `options`: Passes providers from config into SDK server call

## v2.1.2-alpha.0

- `getTokenSupply`, `getTokenUserBalance`, `getUserPools`: Correctly passes `options` to backend request and uses provider from config as default.
Expand Down
2 changes: 1 addition & 1 deletion packages/agents/sdk-wrapper/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@connext/sdk",
"version": "2.1.2-alpha.0",
"version": "2.1.2",
"description": "Client-side package for interacting with the Connext protocol",
"author": "Connext",
"license": "MIT",
Expand Down
24 changes: 21 additions & 3 deletions packages/agents/sdk-wrapper/src/sdkPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class SdkPool extends SdkShared {
chains: this.config.chains,
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
tokenAddress,
Expand Down Expand Up @@ -181,6 +182,7 @@ export class SdkPool extends SdkShared {
chains: this.config.chains,
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
tokenAddress,
Expand All @@ -203,6 +205,7 @@ export class SdkPool extends SdkShared {
chains: this.config.chains,
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
tokenAddress,
Expand All @@ -225,6 +228,7 @@ export class SdkPool extends SdkShared {
chains: this.config.chains,
signerAddress: this.config.signerAddress,
};

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

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

const params: { domainId: string; tokenAddress: string; amountX: string; amountY: string } = {
domainId,
tokenAddress,
Expand All @@ -302,6 +318,7 @@ export class SdkPool extends SdkShared {
chains: this.config.chains,
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
amountX,
Expand Down Expand Up @@ -335,7 +352,6 @@ export class SdkPool extends SdkShared {
const _options = options ?? {
chains: this.config.chains,
signerAddress: this.config.signerAddress,
originProviderUrl: this.config.chains[domainId].providers?.[0],
};
const params = {
domainId,
Expand All @@ -356,7 +372,6 @@ export class SdkPool extends SdkShared {
const _options = options ?? {
chains: this.config.chains,
signerAddress: this.config.signerAddress,
originProviderUrl: this.config.chains[domainId].providers?.[0],
};
const params = {
domainId,
Expand Down Expand Up @@ -400,6 +415,7 @@ export class SdkPool extends SdkShared {
chains: this.config.chains,
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
tokenAddress,
Expand Down Expand Up @@ -427,6 +443,7 @@ export class SdkPool extends SdkShared {
chains: this.config.chains,
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
tokenAddress,
Expand Down Expand Up @@ -558,6 +575,7 @@ export class SdkPool extends SdkShared {
chains: this.config.chains,
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
tokenAddress,
Expand All @@ -584,6 +602,7 @@ export class SdkPool extends SdkShared {
chains: this.config.chains,
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
tokenAddress,
Expand Down Expand Up @@ -633,7 +652,6 @@ export class SdkPool extends SdkShared {
const _options = options ?? {
chains: this.config.chains,
signerAddress: this.config.signerAddress,
originProviderUrl: this.config.chains[domainId].providers?.[0],
};
const params = {
domainId,
Expand Down
1 change: 1 addition & 0 deletions packages/agents/sdk-wrapper/src/sdkShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export class SdkShared {
chains: this.config.chains,
signerAddress: this.config.signerAddress,
};

const params = {
domainId,
assetId,
Expand Down
3 changes: 0 additions & 3 deletions packages/agents/sdk-wrapper/test/sdkPool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,6 @@ describe("#SDKPool", () => {
options: {
chains: mockConfig.chains,
signerAddress: mockConfig.signerAddress,
originProviderUrl: mockConfig.chains[mock.domain.A].providers?.[0],
},
};
const mockServerRes = {
Expand Down Expand Up @@ -874,7 +873,6 @@ describe("#SDKPool", () => {
options: {
chains: mockConfig.chains,
signerAddress: mockConfig.signerAddress,
originProviderUrl: mockConfig.chains[mock.domain.A].providers?.[0],
},
};
const mockServerRes = {
Expand Down Expand Up @@ -1698,7 +1696,6 @@ describe("#SDKPool", () => {
options: {
chains: mockConfig.chains,
signerAddress: mockConfig.signerAddress,
originProviderUrl: mockConfig.chains[mock.domain.A].providers?.[0],
},
};
const mockServerRes = [
Expand Down
2 changes: 1 addition & 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
4 changes: 4 additions & 0 deletions packages/agents/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Next Release

## v2.1.2

- `options`: SDK takes passed in provider

## v2.1.2-alpha.0

- `getUserPools`: Takes `options?` param
Expand Down
2 changes: 1 addition & 1 deletion packages/agents/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@connext/sdk-core",
"version": "2.1.2-alpha.0",
"version": "2.1.2",
"description": "Client-side package for interacting with the Connext protocol",
"author": "Connext",
"license": "MIT",
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
32 changes: 27 additions & 5 deletions packages/agents/sdk/src/sdkShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,21 @@ export class SdkShared {

const connextAddress = await this.getDeploymentAddress(domainId, "connext");

const provider = options?.originProviderUrl
? new providers.StaticJsonRpcProvider(options.originProviderUrl)
let providerURL = options?.originProviderUrl ?? options?.originProviderUrl;

if (!providerURL && options?.chains) {
Object.keys(options.chains).forEach((domain) => {
if (domain !== domainId) {
return;
}
providerURL = options.chains?.[domain].providers?.[0];
});
}

const provider = providerURL
? new providers.StaticJsonRpcProvider(providerURL)
: await this.getProvider(domainId);

return Connext__factory.connect(connextAddress, provider);
},
{ promise: true },
Expand All @@ -151,9 +163,19 @@ export class SdkShared {
throw new ProviderMissing(domainId);
}

const provider = options?.originProviderUrl
? new providers.StaticJsonRpcProvider(options.originProviderUrl)
: await this.getProvider(domainId);
let providerURL = options?.originProviderUrl ?? options?.originProviderUrl;

if (!providerURL && options?.chains) {
Object.keys(options.chains).forEach((domain) => {
if (domain !== domainId) {
return;
}
providerURL = options.chains?.[domain].providers?.[0];
});
}

const provider = providerURL ? new providers.StaticJsonRpcProvider(providerURL) : await this.getProvider(domainId);

return IERC20__factory.connect(tokenAddress, provider);
}

Expand Down
3 changes: 3 additions & 0 deletions packages/agents/sdk/test/sdkShared.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ describe("SdkShared", () => {
stub(sdkShared, "getProvider").resolves(undefined);
const options = {
originProviderUrl: "http://example.com",
chains: {
[mock.domain.A]: { providers: ["http://example.com"] },
},
};

const res = await sdkShared.getERC20(mock.domain.A, mock.asset.A.address, options);
Expand Down