Skip to content

Commit

Permalink
Osmosis: Return feeTier instead of pool.fee from poolPositions(). Wra…
Browse files Browse the repository at this point in the history
…pped getCurrentBlock() and return 0 when HTTP429 back from RPC
  • Loading branch information
chasevoorhees committed Mar 16, 2024
1 parent 3db1553 commit 045af2b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 63 deletions.
124 changes: 67 additions & 57 deletions src/chains/osmosis/osmosis.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,66 +670,76 @@ export class OsmosisController {
}

static async poll(osmosis: Osmosis, req: CosmosPollRequest) {
if (req.txHash){
const transaction = await osmosis.getTransaction(req.txHash);
const currentBlock = await osmosis.getCurrentBlockNumber();

//@ts-ignore cosmojs models again
var pool_id = undefined;
var position_id = undefined;
//@ts-ignore cosmojs models again
if (transaction.txResponse.logs){
//@ts-ignore cosmojs models again
transaction.txResponse.logs.forEach((log) => {
//@ts-ignore cosmojs models again
const create_position_event = log.events.find(({ type }) => type === 'create_position');
if (create_position_event){
//@ts-ignore cosmojs models again
const pool_id_attribute = create_position_event.attributes.find(({ key }) => key === 'pool_id');
if (pool_id_attribute){
pool_id = pool_id_attribute.value
}
//@ts-ignore cosmojs models again
const position_id_attribute = create_position_event.attributes.find(({ key }) => key === 'position_id');
if (position_id_attribute){
position_id = position_id_attribute.value
try{
if (req.txHash){
const transaction = await osmosis.getTransaction(req.txHash);
const currentBlock = await osmosis.getCurrentBlockNumber();

//@ts-ignore cosmojs models again
var pool_id = undefined;
var position_id = undefined;
//@ts-ignore cosmojs models again
if (transaction.txResponse.logs){
//@ts-ignore cosmojs models again
transaction.txResponse.logs.forEach((log) => {
//@ts-ignore cosmojs models again
const create_position_event = log.events.find(({ type }) => type === 'create_position');
if (create_position_event){
//@ts-ignore cosmojs models again
const pool_id_attribute = create_position_event.attributes.find(({ key }) => key === 'pool_id');
if (pool_id_attribute){
pool_id = pool_id_attribute.value
}
//@ts-ignore cosmojs models again
const position_id_attribute = create_position_event.attributes.find(({ key }) => key === 'position_id');
if (position_id_attribute){
position_id = position_id_attribute.value
}
}
}
})
}
var tokenId = position_id;
if (position_id == undefined){
tokenId = pool_id;
}

var txStatus = unconfirmedTransaction;
//@ts-ignore cosmojs models again
if (transaction.txResponse.code == successfulTransaction){
txStatus = 1; // clientside this is a successful tx
}
//@ts-ignore cosmojs models again
else if (transaction.txResponse.code != unconfirmedTransaction){
//@ts-ignore cosmojs models again
txStatus = transaction.txResponse.code; // any other failure
}
return {
txStatus: txStatus,
txReceipt: null,
tokenId: Number(tokenId),
txHash: req.txHash,
currentBlock,
//@ts-ignore cosmojs models again
txBlock: Number(transaction.txResponse.height.toString()),
//@ts-ignore cosmojs models again
gasUsed: Number(transaction.txResponse.gasUsed.toString()),
//@ts-ignore cosmojs models again
gasWanted: Number(transaction.txResponse.gasWanted.toString()),
txData: decodeTxRaw(transaction.tx),
};

})
}
var tokenId = position_id;
if (position_id == undefined){
tokenId = pool_id;
}

var txStatus = unconfirmedTransaction;
//@ts-ignore cosmojs models again
if (transaction.txResponse.code == successfulTransaction){
txStatus = 1; // clientside this is a successful tx
}
//@ts-ignore cosmojs models again
else if (transaction.txResponse.code != unconfirmedTransaction){
//@ts-ignore cosmojs models again
txStatus = transaction.txResponse.code; // any other failure
}
return {
txStatus: txStatus,
txReceipt: null,
tokenId: Number(tokenId),
txHash: req.txHash,
currentBlock,
//@ts-ignore cosmojs models again
txBlock: Number(transaction.txResponse.height.toString()),
//@ts-ignore cosmojs models again
gasUsed: Number(transaction.txResponse.gasUsed.toString()),
//@ts-ignore cosmojs models again
gasWanted: Number(transaction.txResponse.gasWanted.toString()),
txData: decodeTxRaw(transaction.tx),
};

}

} catch (err) {
logger.debug(err);
// throw new HttpException(
// 500,
// LOAD_WALLET_ERROR_MESSAGE + err,
// LOAD_WALLET_ERROR_CODE
// );
}
return {
txHash: '',
txHash: req.txHash!,
txStatus: 0,
txBlock: 0,
gasUsed: 0,
Expand Down
16 changes: 10 additions & 6 deletions src/chains/osmosis/osmosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2361,8 +2361,7 @@ export class Osmosis extends CosmosBase implements Cosmosish{
returnObj.poolShares = clPosition.position.liquidity
returnObj.unclaimedToken0 = unclaimedToken0.toString()
returnObj.unclaimedToken1 = unclaimedToken1.toString()
const clPositionPool = extendedPools.find((pl) => pl.id.toString() === clPosition.position.poolId.toString());
returnObj.fee = clPositionPool?.fees7D.toString()
returnObj.fee = this.feeTier
}
// not returning GAMM positons here; problematic for strat and apparently this is amm-liquidity route only
// else if (tokenId && returnPools.length > 0){ // we got a poolId but it was for a GAMM pool - so yes poolShares
Expand Down Expand Up @@ -2391,10 +2390,15 @@ export class Osmosis extends CosmosBase implements Cosmosish{


async getCurrentBlockNumber(): Promise<number>{
const client = await CosmWasmClient
.connect(this.rpcUrl);
const getHeight = await client.getHeight()
return getHeight;
try{
const client = await CosmWasmClient
.connect(this.rpcUrl);
const getHeight = await client.getHeight()
return getHeight;
} catch (error) {
console.debug(error);
return 0 // cosmwasm likes to throw 429 on the above call, and we don't actually use this number anywhere on the strat side so this should be ok
}
}

/**
Expand Down

0 comments on commit 045af2b

Please sign in to comment.