Skip to content

Commit 3e05d73

Browse files
authored
Update incentive (#506)
* update incentive * update version
1 parent 6288d1c commit 3e05d73

6 files changed

Lines changed: 16 additions & 23 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535
"typescript": "^5.0.4"
3636
},
3737
"packageManager": "yarn@3.5.0",
38-
"stableVersion": "4.1.9-7"
38+
"stableVersion": "4.1.9-8"
3939
}

packages/sdk/src/incentive/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ export class Incentive implements BaseSDK {
122122
]);
123123

124124
return data.map((item) => {
125-
const rawId = item[0].args[0];
126-
const id = getPoolId(rawId);
127-
const type = rawId.isDex ? IncentiveType.DEX : IncentiveType.LOANS;
128-
const collateral = tokens[forceToCurrencyName(getPoolToken(rawId))];
125+
const raw = item[0].args[0];
126+
const id = getPoolId(raw);
127+
const type = raw.isDex ? IncentiveType.DEX : raw.isLoans ? IncentiveType.LOANS : IncentiveType.Earning;
128+
const collateral = tokens[forceToCurrencyName(getPoolToken(raw))];
129129
const totalShares = FixedPointNumber.fromInner(item[1].totalShares.toString(), collateral.decimals);
130130

131131
// format rewards infomations
@@ -142,7 +142,7 @@ export class Incentive implements BaseSDK {
142142
};
143143
});
144144

145-
return { collateral, type, id, rawId, totalShares, rewards };
145+
return { collateral, type, id, raw, totalShares, rewards };
146146
});
147147
})
148148
);
@@ -180,8 +180,8 @@ export class Incentive implements BaseSDK {
180180

181181
return combineLatest({
182182
info: of(info),
183-
sharesAndWithdrawn: this.storages.userSharesAndWithdrawnRewards(info.rawId, address).observable,
184-
pendingRewards: this.storages.pendingRewards(info.rawId, address).observable
183+
sharesAndWithdrawn: this.storages.userSharesAndWithdrawnRewards(info.raw, address).observable,
184+
pendingRewards: this.storages.pendingRewards(info.raw, address).observable
185185
});
186186
}),
187187
map(({ info, sharesAndWithdrawn, pendingRewards }) => {
@@ -312,7 +312,7 @@ export class Incentive implements BaseSDK {
312312
return this.subscribeAllIncentivePools().pipe(
313313
map((data) => {
314314
return data.find((item) => {
315-
return item.type === type && forceToCurrencyName(getPoolToken(item.rawId)) === forceToCurrencyName(currency);
315+
return item.type === type && forceToCurrencyName(getPoolToken(item.raw)) === forceToCurrencyName(currency);
316316
});
317317
})
318318
);

packages/sdk/src/incentive/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { Wallet } from '../wallet';
44

55
export enum IncentiveType {
66
'LOANS',
7-
'DEX'
7+
'DEX',
8+
'Earning'
89
}
910

1011
export interface IncentiveConfigs {
@@ -50,7 +51,7 @@ export interface BaseIncentivePool {
5051
// pool id
5152
id: string;
5253
// raw pool id
53-
rawId: ModuleSupportIncentivesPoolId;
54+
raw: ModuleSupportIncentivesPoolId;
5455
// the colateral token required by the pool
5556
collateral: Token;
5657
// total shares belone to the pool
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
import { forceToCurrencyName } from '@acala-network/sdk-core';
21
import { ModuleSupportIncentivesPoolId } from '@polkadot/types/lookup';
32

43
export function getPoolId(pool: ModuleSupportIncentivesPoolId): string {
5-
if (pool.isDex) {
6-
return `dex-${forceToCurrencyName(pool.asDex)}`;
7-
}
8-
9-
if (pool.isLoans) {
10-
return `loans-${forceToCurrencyName(pool.asLoans)}`;
11-
}
12-
13-
return 'unknown';
4+
return pool.toHex();
145
}

packages/sdk/src/incentive/utils/get-pool-token.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export function getPoolToken(poolId: ModuleSupportIncentivesPoolId): AcalaPrimit
55

66
if (poolId.isLoans) return poolId.asLoans;
77

8+
if ((poolId as any).isEarning) return (poolId as any).asEarning;
9+
810
// always success, never run belown
911
return undefined as unknown as AcalaPrimitivesCurrencyCurrencyId;
1012
}

tsconfig.base.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
"@acala-network/sdk-payment": ["packages/sdk-payment/src"],
3131
"@acala-network/sdk-payment/*": ["packages/sdk-payment/src/*"],
3232
"@acala-network/wormhole-portal": ["packages/wormhole-portal/src"],
33-
"@acala-network/wormhole-portal/*": ["packages/wormhole-portal/src/*"],
34-
"@polkadot/types/lookup": ["node_modules/@acala-network/types/lookup/types-acala.d.ts"],
33+
"@acala-network/wormhole-portal/*": ["packages/wormhole-portal/src/*"]
3534
},
3635
},
3736
}

0 commit comments

Comments
 (0)