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

settlementCurrencies in createSingleSaleOffer #581

Open
valela777 opened this issue Mar 20, 2024 · 6 comments
Open

settlementCurrencies in createSingleSaleOffer #581

valela777 opened this issue Mar 20, 2024 · 6 comments

Comments

@valela777
Copy link

Hi. I want to offer cards for sale in WEI and EUR. It works this way manually, but not through the API.

const prepareOfferInput = { type: "SINGLE_SALE_OFFER", sendAssetIds: [sendCard], receiveAssetIds: [], settlementCurrencies:['EUR','WEI'], receiveAmount: { amount: String(receiveWei), currency: 'WEI', }, clientMutationId: crypto.randomBytes(8).join(""), };

const createSingleSaleOfferInput = { approvals, dealId: crypto.randomBytes(8).join(""), assetId: sendCard, settlementCurrencies:['EUR','WEI'], receiveAmount: { amount: String(receiveWei), currency: 'WEI', }, clientMutationId: crypto.randomBytes(8).join(''), };

this way I get different errors

@valela777
Copy link
Author

@redox help

@valela777
Copy link
Author

ClientError: Fields "amount" conflict because they return conflicting types "WeiAmount!" and "Int!". Use different aliases on the fields to fetch both if this was intentional

import { GraphQLClient, gql } from 'graphql-request';
import crypto from 'crypto';
import { ActionCable } from '@sorare/actioncable';
import fs from 'fs';

import {
  authorizationRequestFragment,
  buildApprovals,
} from './authorizations1.js';



const sendAssetId = "xxxx"
const settlementCurrencies = ["WEI","EUR"]
const receiveCurrency = 'WEI'
const receiveAmount = '10000000000000000'



const PrepareOffer = gql`
  mutation PrepareAcceptOffer($input: prepareAcceptOfferInput) {
    prepareAcceptOffer(input: $input) {
      authorizations {
        ...AuthorizationRequestFragment
      }
      errors {
        message
      }
    }
  }
  ${authorizationRequestFragment}
`;

const CreateSingleSaleOffer = gql`
  mutation CreateSingleSaleOffer($input: createSingleSaleOfferInput!) {
    createSingleSaleOffer(input: $input) {
      tokenOffer {
        id
        startDate
        endDate
      }
      errors {
        message
      }
    }
  }
`;

async function main() {
  const graphQLClient = new GraphQLClient(
    'https://api.sorare.com/federation/graphql',
    {
      headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer exxx',
      'JWT-AUD': 'xxxx',
      'APIKEY': 'xxx'
      },
    }
  );

  const prepareOfferInput = {
    type: 'SINGLE_SALE_OFFER',
    sendAssetIds: [sendAssetId],
    receiveAssetIds: [],
    settlementCurrencies: settlementCurrencies,
    receiveAmount: {
      amount: receiveAmount,
      currency: receiveCurrency,
    },
    clientMutationId: crypto.randomBytes(8).join(''),
  };

  const prepareOfferData = await graphQLClient.request(PrepareOffer, {
    input: prepareOfferInput,
  });
  const prepareOffer = prepareOfferData['prepareOffer'];
  if (prepareOffer['errors'].length > 0) {
    prepareOffer['errors'].forEach(error => {
      console.error(error['message']);
    });
    process.exit(2);
  }

  const authorizations = prepareOffer['authorizations'];
  console.log(authorizations)
  const approvals = buildApprovals('xxxx', authorizations);

  const createSingleSaleOfferInput = {
    approvals,
    dealId: crypto.randomBytes(8).join(''),
    assetId: sendAssetId,
    settlementCurrencies: settlementCurrencies,
    receiveAmount: { amount: receiveAmount, currency: receiveCurrency },
    clientMutationId: crypto.randomBytes(8).join(''),
  };
  const createSingleSaleOfferData = await graphQLClient.request(
    CreateSingleSaleOffer,
    { input: createSingleSaleOfferInput }
  );
  console.log(createSingleSaleOfferData);

  const createSingleSaleOffer =
    createSingleSaleOfferData['createSingleSaleOffer'];

  if (createSingleSaleOffer['errors'].length > 0) {
    createSingleSaleOffer['errors'].forEach(error => {
      console.error(error['message']);
    });
    process.exit(2);
  }

  console.log('Success!');
}

main().catch(error => console.error(error));

@jmallot21
Copy link

Have you tried passing your variable from WEI to int ?
Like that :
const receiveAmount = 10000000000000000

@valela777
Copy link
Author

Have you tried passing your variable from WEI to int ? Like that : const receiveAmount = 10000000000000000

Variable $input of type prepareOfferInput! was provided invalid value for receiveAmount.amount (Could not coerce value 1300000000000000 to String

I'm currently using this code:

const PrepareOffer = gql`
mutation PrepareOffer($input: prepareOfferInput!) {
  prepareOffer(input: $input) {
    authorizations {
      fingerprint
      request {
      ... on StarkexLimitOrderAuthorizationRequest {
        vaultIdSell
        vaultIdBuy
        amountSell
        amountBuy
        tokenSell
        tokenBuy
        nonce
        expirationTimestamp
        feeInfo {
          feeLimit
          tokenId
          sourceVaultId
        }
      }
      }
    }
    errors {
      message
    }
  }
}
`;



  const prepareOfferInput = {
    type: 'SINGLE_SALE_OFFER',
    sendAssetIds: ["0x0400e41a047f755d6f598c7abf6c61ea0598"],
    receiveAssetIds: [],
    receiveAmount: { amount: '10000000000000000', currency: 'WEI' },

    clientMutationId: crypto.randomBytes(8).join(''),
  };

  const prepareOfferData = await graphQLClient.request(PrepareOffer, {
    input: prepareOfferInput,
  });
 const prepareOffer = prepareOfferData['prepareOffer'];
console.log(prepareOffer['authorizations'])
= [
  {
    fingerprint: 'f5bece6edb836903721c4444fc8',
    request: {
      vaultIdSell: 20543973,
      vaultIdBuy: 4380978,
      amountSell: '1',
      amountBuy: '95004400',
      tokenSell: '0x0400e41a047f5556bf825c12587',
      tokenBuy: '0xb33355555520c6801a27fba6',
      nonce: 234344,
      expirationTimestamp: 47643434771,
      feeInfo: null
    }
  }
]

  const approvals = buildApprovals('xxxxxxx', authorizations);

  const createSingleSaleOfferInput = {
    approvals,
    dealId: crypto.randomBytes(8).join(''),
    assetId: "xxxxxxxxx",
    settlementCurrencies: ['WEI', 'EUR'],
    receiveAmount: { amount: '10000000000000000', currency: 'WEI' },
    clientMutationId: crypto.randomBytes(8).join(''),
    duration:604800
  };

  const createSingleSaleOfferData = await graphQLClient.request(
    CreateSingleSaleOffer,
    { input: createSingleSaleOfferInput }
  );

Missing approval for {:order_type=>0, :public_key=>"xxxxxxx", :token_buy=>"xxxxxx", :token_sell=>"xxxxxx", :amount_buy=>"950000", :amount_sell=>"1", :vault_id_buy=>4380978, :vault_id_sell=>18677760, :expiration_timestamp=>476771}

authorizations.js

const buildApproval = (privateKey, fingerprint, authorizationRequest) => {
  const signature = signAuthorizationRequest(privateKey, authorizationRequest);
    return {
      fingerprint,
      starkexLimitOrderApproval: {
        nonce: authorizationRequest.nonce,
        expirationTimestamp: authorizationRequest.expirationTimestamp,
        signature,
      },
    };
};

@Redace762
Copy link

@valela777
Copy link
Author

the problem remains..Please show prepareOfferInput and createSingleSaleOfferInput with wei and fiat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants