Skip to content

Commit 03c80d5

Browse files
authored
Merge pull request #3432 from JoinColony/feat/liquidation-address-overrides
Feat: Allow overriding user's liquidation address
2 parents dd6d8ce + 4a90d8a commit 03c80d5

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

amplify/backend/function/bridgeXYZMutation/src/handlers/getUserLiquidationAddress.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
const fetch = require('cross-fetch');
21
const { graphqlRequest } = require('../utils');
32
const { getLiquidationAddresses, getExternalAccounts } = require('./utils');
43

54
const { getUser } = require('../graphql');
65

76
const getUserLiquidationAddressHandler = async (
87
event,
9-
{ appSyncApiKey, apiKey, apiUrl, graphqlURL },
8+
{
9+
appSyncApiKey,
10+
apiKey,
11+
apiUrl,
12+
graphqlURL,
13+
temp_liquidationAddressOverrides,
14+
},
1015
) => {
1116
const userAddress = event.arguments.userAddress;
1217

18+
try {
19+
const overrides = JSON.parse(temp_liquidationAddressOverrides);
20+
if (overrides[userAddress]) {
21+
return overrides[userAddress];
22+
}
23+
} catch (e) {
24+
console.log('Error parsing liquidation address overrides: ', e);
25+
}
26+
1327
const { data: graphQlData } = await graphqlRequest(
1428
getUser,
1529
{
@@ -25,7 +39,11 @@ const getUserLiquidationAddressHandler = async (
2539
return null;
2640
}
2741

28-
const externalAccounts = await getExternalAccounts(apiUrl, apiKey, bridgeCustomerId);
42+
const externalAccounts = await getExternalAccounts(
43+
apiUrl,
44+
apiKey,
45+
bridgeCustomerId,
46+
);
2947
const firstAccount = externalAccounts?.[0];
3048

3149
if (!firstAccount) {

amplify/backend/function/bridgeXYZMutation/src/index.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,24 @@ let graphqlURL = 'http://localhost:20002/graphql';
1818
let appSyncApiKey = 'da2-fakeApiId123456';
1919
let apiUrl = process.env.BRIDGE_API_URL;
2020
let apiKey = process.env.BRIDGE_API_KEY;
21+
let temp_liquidationAddressOverrides =
22+
process.env.LIQUIDATION_ADDRESS_OVERRIDES;
2123

2224
const setEnvVariables = async () => {
2325
if (!isDev) {
2426
const { getParams } = require('/opt/nodejs/getParams');
25-
[appSyncApiKey, apiKey, apiUrl, graphqlURL] = await getParams([
27+
[
28+
appSyncApiKey,
29+
apiKey,
30+
apiUrl,
31+
graphqlURL,
32+
temp_liquidationAddressOverrides,
33+
] = await getParams([
2634
'appsyncApiKey',
2735
'bridgeXYZApiKey',
2836
'bridgeXYZApiUrl',
2937
'graphqlUrl',
38+
'liquidationAddressOverrides',
3039
]);
3140
}
3241
};
@@ -68,7 +77,13 @@ exports.handler = async (event) => {
6877
handlers[path] || handlers[event.fieldName] || handlers.default;
6978

7079
try {
71-
return await handler(event, { appSyncApiKey, apiKey, apiUrl, graphqlURL });
80+
return await handler(event, {
81+
appSyncApiKey,
82+
apiKey,
83+
apiUrl,
84+
graphqlURL,
85+
temp_liquidationAddressOverrides,
86+
});
7287
} catch (error) {
7388
console.error(
7489
`bridgeXYZMutation handler ${handler.name} failed with error: ${error}`,

amplify/backend/function/colonycdappSSMAccess/lib/nodejs/getParams.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const ParamNames = {
1616
etherscanApiKey: `%2Famplify%2Fcdapp%2F${ENV}%2FETHERSCAN_API_KEY`,
1717
bridgeXYZApiKey: `%2Famplify%2Fcdapp%2F${ENV}%2FBRIDGEXYZ_API_KEY`,
1818
bridgeXYZApiUrl: `%2Famplify%2Fcdapp%2F${ENV}%2FBRIDGEXYZ_API_URL`,
19+
liquidationAddressOverrides: `%2Famplify%2Fcdapp%2F${ENV}%2FLIQUIDATION_ADDRESS_OVERRIDES`,
1920
};
2021

2122
const getParam = async (paramName) => {

0 commit comments

Comments
 (0)