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/Plenty: Maintenance of Tezos and Plenty connectors #223

Merged
merged 5 commits into from Nov 13, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/chains/tezos/tezos.base.ts
Expand Up @@ -54,6 +54,7 @@ export class TezosBase {

private tzktURL: string;
private _tzktApiClient: TzktApiClient;
public ctezAdminAddress: string;

constructor(network: string) {
const config = getTezosConfig('tezos', network);
Expand All @@ -62,6 +63,7 @@ export class TezosBase {
this.tzktURL = config.network.tzktURL;
this.tokenListType = config.network.tokenListType;
this.tokenListSource = config.network.tokenListSource;
this.ctezAdminAddress = config.network.ctezAdminAddress;
this._provider = new TezosToolkit(this.rpcUrl);
this._rpcClient = new RpcClient(this.rpcUrl);
this._tzktApiClient = new TzktApiClient(this.tzktURL);
Expand Down Expand Up @@ -117,10 +119,10 @@ export class TezosBase {
return this._contractMap[address];
}

// returns the contract storage for a given address (cached for 15 seconds)
// returns the contract storage for a given address (cached for 12 seconds)
async getContractStorage(address: string) {
const timestamp = Date.now();
if (!this._contractStorageMap[address] || timestamp - this._contractStorageMap[address].timestamp > 15000) {
if (!this._contractStorageMap[address] || timestamp - this._contractStorageMap[address].timestamp > 12000) {
const contract = await this.getContract(address);
this._contractStorageMap[address] = {
storage: await contract.storage(),
Expand Down
4 changes: 4 additions & 0 deletions src/chains/tezos/tezos.config.ts
Expand Up @@ -9,6 +9,7 @@ export interface NetworkConfig {
tokenListType: TokenListType;
tokenListSource: string;
tzktURL: string;
ctezAdminAddress: string;
}

export interface Config {
Expand Down Expand Up @@ -41,6 +42,9 @@ export function getTezosConfig(chainName: string, networkName: string): Config {
tzktURL: ConfigManagerV2.getInstance().get(
chainName + '.networks.' + network + '.tzktURL'
),
ctezAdminAddress: ConfigManagerV2.getInstance().get(
chainName + '.networks.' + network + '.ctezAdmin'
)
},
nativeCurrencySymbol: ConfigManagerV2.getInstance().get(
chainName + '.networks.' + network + '.nativeCurrencySymbol'
Expand Down
5 changes: 0 additions & 5 deletions src/connectors/plenty/plenty.config.ts
Expand Up @@ -8,7 +8,6 @@ export namespace PlentyConfig {
poolsApi: (network: string) => string;
analyticsApi: (network: string) => string;
routerAddress: (network: string) => string;
ctezAdminAddress: (network: string) => string;
tradingTypes: Array<string>;
availableNetworks: Array<AvailableNetworks>;
chainType: string;
Expand All @@ -33,10 +32,6 @@ export namespace PlentyConfig {
ConfigManagerV2.getInstance().get(
'plenty.contractAddresses.' + network + '.router'
),
ctezAdminAddress: (network: string) =>
ConfigManagerV2.getInstance().get(
'plenty.contractAddresses.' + network + '.ctezAdmin'
),
tradingTypes: ['AMM'],
chainType: 'TEZOS',
availableNetworks: [
Expand Down
14 changes: 4 additions & 10 deletions src/connectors/plenty/plenty.ts
Expand Up @@ -19,16 +19,14 @@ export class Plenty {
private _tokenList: Record<string, IConfigToken> = {};
private _pools: Record<string, IConfigPool> = {};
private _ready: boolean = false;
private _skipTokens: string[] = ['SEB', 'PEPE'];
public ctezAdminAddress: string;
private _skipTokens: string[] = ['SEB', 'PEPE', 'TKEY-X'];
public isPlenty = true;

constructor(network: string) {
const config = PlentyConfig.config;
this._router = config.routerAddress(network);
this._poolsApi = config.poolsApi(network);
this._analyticsApi = config.analyticsApi(network);
this.ctezAdminAddress = config.ctezAdminAddress(network);
this._gasLimitEstimate = config.gasLimitEstimate;
}

Expand All @@ -50,7 +48,7 @@ export class Plenty {
* @param address Token address
*/
public getTokenBySymbol(symbol: string): IConfigToken {
return this._tokenList[symbol];
return this._tokenList[symbol.toLocaleUpperCase()];
}

public async init() {
Expand All @@ -63,7 +61,7 @@ export class Plenty {
pool.token2.symbol = pool.token2.symbol.toUpperCase();
pool.token1.pairs = pool.token1.pairs.map((pair) => pair.toUpperCase());
pool.token2.pairs = pool.token2.pairs.map((pair) => pair.toUpperCase());
if (pool.token1.symbol in this._skipTokens || pool.token2.symbol in this._skipTokens)
if (this._skipTokens.includes(pool.token1.symbol) || this._skipTokens.includes(pool.token2.symbol))
continue;

let tokensKey = pool.token1.symbol + '-' + pool.token2.symbol;
Expand Down Expand Up @@ -105,10 +103,6 @@ export class Plenty {
return await apiResponse.json();
}

public async ctezContract(tezos: Tezosish): Promise<any> {
return await tezos.getContract(this.ctezAdminAddress);
}

public get tokenList(): Record<string, IConfigToken> {
return this._tokenList;
}
Expand Down Expand Up @@ -245,7 +239,7 @@ export class Plenty {
return {
expectedAmount: path.tokenOutAmount,
trade: {
executionPrice: path.exchangeRate,
executionPrice: BigNumber(1).dividedBy(path.exchangeRate),
routeParams: path,
amountIn: path.tokenOutAmount.multipliedBy(10 ** quoteToken.decimals),
}
Expand Down
2 changes: 1 addition & 1 deletion src/connectors/plenty/utils/wrappers.ts
Expand Up @@ -410,7 +410,7 @@ export const loadSwapDataWrapper = async (
(tokenIn === "XTZ" && tokenOut === "CTEZ") ||
(tokenIn === "CTEZ" && tokenOut === "XTZ")
) {
const ctezAdmin = await tezos.getContractStorage(plenty.ctezAdminAddress);
const ctezAdmin = await tezos.getContractStorage(tezos.ctezAdminAddress);
swapData = loadSwapDataTezCtez(dex, poolAnalytics, tokenIn, tokenOut);
swapData.target = ctezAdmin.target;
} else {
Expand Down
6 changes: 1 addition & 5 deletions src/services/schema/plenty-schema.json
Expand Up @@ -22,15 +22,11 @@
},
"router": {
"type": "string"
},
"ctezAdmin": {
"type": "string"
}
},
"required": [
"poolsApi",
"router",
"ctezAdmin"
"router"
],
"additionalProperties": false
}
Expand Down
6 changes: 5 additions & 1 deletion src/services/schema/tezos-schema.json
Expand Up @@ -28,6 +28,9 @@
},
"tzktURL": {
"type": "string"
},
"ctezAdmin": {
"type": "string"
}
},
"required": [
Expand All @@ -36,7 +39,8 @@
"nodeURL",
"tokenListType",
"tokenListSource",
"tzktURL"
"tzktURL",
"ctezAdmin"
],
"additionalProperties": false
}
Expand Down
8 changes: 8 additions & 0 deletions src/templates/lists/tezos.mainnet.tokens.json
Expand Up @@ -511,6 +511,14 @@
"decimals": 12,
"standard": "FA2",
"tokenId": 0
},
{
"name": "Tezos Domains Governance Token",
"symbol": "TED",
"decimals": 6,
"standard": "FA2",
"address": "KT1GY5qCWwmESfTv9dgjYyTYs2T5XGDSvRp1",
"tokenId": 0
}
]
}
3 changes: 1 addition & 2 deletions src/templates/plenty.yml
Expand Up @@ -10,6 +10,5 @@ gasLimitEstimate: 15000
contractAddresses:
mainnet:
poolsApi: 'https://config.mainnet.plenty.network/pools'
analyticsApi: 'https://api.analytics.plenty.network/analytics/pools'
analyticsApi: 'https://api.plenty.network/analytics/pools'
router: 'KT1WPctQmrbGDf5Md2xmFGQGUSvQgao18vK4'
ctezAdmin: 'KT1GWnsoFZVHGh7roXEER3qeCcgJgrXT3de2'
4 changes: 3 additions & 1 deletion src/templates/tezos.yml
Expand Up @@ -5,10 +5,11 @@ networks:
mainnet:
chainID: 'mainnet'
nativeCurrencySymbol: 'XTZ'
nodeURL: 'https://rpc.tzbeta.net'
nodeURL: 'https://mainnet.tezos.marigold.dev'
tokenListType: 'FILE'
tokenListSource: 'conf/lists/tezos.mainnet.tokens.json'
tzktURL: 'https://api.tzkt.io'
ctezAdmin: 'KT1GWnsoFZVHGh7roXEER3qeCcgJgrXT3de2'

ghostnet:
chainID: 'ghostnet'
Expand All @@ -17,6 +18,7 @@ networks:
tokenListType: 'FILE'
tokenListSource: 'conf/lists/tezos.ghostnet.tokens.json'
tzktURL: 'https://api.ghostnet.tzkt.io'
ctezAdmin: 'KT1CYRQciQpUnyPPEXBR6f65tnyidao76kdn'

manualGasPrice: 123456 # Refer https://tezos.stackexchange.com/questions/2176/how-to-calculate-price-of-gas/2177#2177
gasLimitTransaction: 100000
7 changes: 0 additions & 7 deletions test-bronze/connectors/plenty/plenty.test.ts
Expand Up @@ -62,13 +62,6 @@ describe('Plenty', () => {
});
});

describe('ctezContract', () => {
it('should return the ctez contract', async () => {
const contract = await plenty.ctezContract(tezos);
expect(contract).toBeDefined();
});
});

describe('tokenList', () => {
it('should return the token list', () => {
const tokenList = plenty.tokenList;
Expand Down